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