LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-06-2005, 01:43 PM   #1
Chrax
Member
 
Registered: Apr 2004
Distribution: Dapper
Posts: 167

Rep: Reputation: 31
Of Perl CGI scripts and Sendmail


Hey all. I'm working on a script to handle web forms, and email their contents to me via sendmail. I do not want to have to type the parameters out in the script itself, because that would make it terribly unflexible. But when I switched to having it just print every parameter and its value, it began having troubles printing variables after the Subject line.

The following works as expected:
Code:
#!/usr/bin/perl -w
use diagnostics;
use CGI qw(:standard);
                                                                                                                             
print header(-type=>'text/html');
                                                                                                                             
$$_ = param $_ for param();
                                                                                                                             
my($_sendmail,$_to) = ('/usr/sbin/sendmail','user@domain.tld');
                                                                                                                             
open MAIL, "| $_sendmail $_to" or die "Can't open sendmail: message = '$!'";
print MAIL "To: $_to\n";
print MAIL "From: Chrax\n";
print MAIL "Subject: ", param('Subject'), "\n";
print MAIL "Test\n\nChris\n";
close MAIL or die "Can't close message: message = '$!'";
                                                                                                                             
$body .= "$_: $$_\n" for param();

print << "EOF";
<html>
<head>
</head>
<body>
Thank you for contacting us. You will now be redirected to <a href="/">http://www.analy-sys.com</a>.<br><br>
                                                                                                                             
Your message text was:<br>
<pre>$body</pre>
                                                                                                                             
</body>
</html>
EOF
... but if you switch
Code:
print MAIL "Subject: ", param('Subject'), "\n";
print MAIL "Test\n\nChris\n";
for
Code:
print MAIL "$_: $$_\n" for param();
then the email is sent with no contents, but still a subject line (Subject is the first parameter from the form.).

Now, I have tried creating a single scalar and printing that, but the same problem arises. The only time when the body is printed until the end is when there is no subject line. I have diagnostics and warnings on, so I know that the script is not exiting prematurely. And since the variables are later printed, it is not that they are not being initialized properly.

If anybody knows why this is screwing up and has any advice, I am completely stumped. I am using Perl 5.005_02, but since I'm using a server that I can only telnet into, that's what I'm stuck with.

Thanks,
Chris
 
Old 06-06-2005, 02:02 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
The final header needs to have 2 newlines after it and not one. You'll need to print another newline before starting the message body. Also note that what you are doing could allow users to pass arbirtrary headers to your e-mail.
 
Old 06-06-2005, 04:21 PM   #3
Chrax
Member
 
Registered: Apr 2004
Distribution: Dapper
Posts: 167

Original Poster
Rep: Reputation: 31
Thank you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problems in running cgi/perl scripts... raymond Linux - General 17 02-09-2010 04:06 AM
Running perl scripts outside of cgi-bin ylikone Programming 1 09-08-2005 04:34 AM
Disabling Perl/CGI Scripts totally renegadeavenger Linux - General 1 08-14-2005 07:28 PM
learning to write Perl CGI scripts djgerbavore Programming 1 10-19-2004 12:31 PM
Running Perl/CGI scripts hso_sof Linux - Newbie 3 08-22-2003 10:26 AM


All times are GMT -5. The time now is 01:39 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration