TheJoshMan
07-24-2008, 01:33 AM
Ok, so I keep getting an error when I try to run this cgi.
"Error message:
Premature end of script headers: mail.cgi"
The script:
#!C:\perl\bin\perl.exe
print "Content-type:text/html\n\n";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$mailprog = 'sendmail\sendmail.exe';
$recipient = 'josh_redefined@yahoo.com';
open (MAIL, "|$mailprog -t") or dienice("Can't access $mailprog!\n");
print MAIL "To: $recipient\n";
print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";
print MAIL "Subject: Form Data\n\n";
foreach $key (keys(%FORM)) {
print MAIL "$key = $FORM{$key}\n";
}
close(MAIL);
print <<EndHTML;
<h2>Thank You!</h2>
We appreciate your input, we\'ll get back to you as promptly as possible.<br />
Now, <a href="index.html">GO HOME!</a>
sub dienice {
my($errmsg) = @_;
print "<h2>Oh SNAP!</h2>\n";
print "$errmsg<p>\n";
print "</body></html>\n";
exit;
}
The HTML:
<HTML>
<HEAD>
<TITLE> CGI Mail Test </TITLE>
</HEAD>
<BODY>
<form action="mail.cgi" method="POST">
Your Name: <input type="text" name="name">
Email Address: <input type="text" name="email">
Age: <input type="text" name="age">
Favorite Color: <input type="text" name="favorite_color">
<input type="submit" value="Send">
<input type="reset" value="Clear Form">
</form>
</BODY>
</HTML>
Any thoughts or ideas?
"Error message:
Premature end of script headers: mail.cgi"
The script:
#!C:\perl\bin\perl.exe
print "Content-type:text/html\n\n";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$mailprog = 'sendmail\sendmail.exe';
$recipient = 'josh_redefined@yahoo.com';
open (MAIL, "|$mailprog -t") or dienice("Can't access $mailprog!\n");
print MAIL "To: $recipient\n";
print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";
print MAIL "Subject: Form Data\n\n";
foreach $key (keys(%FORM)) {
print MAIL "$key = $FORM{$key}\n";
}
close(MAIL);
print <<EndHTML;
<h2>Thank You!</h2>
We appreciate your input, we\'ll get back to you as promptly as possible.<br />
Now, <a href="index.html">GO HOME!</a>
sub dienice {
my($errmsg) = @_;
print "<h2>Oh SNAP!</h2>\n";
print "$errmsg<p>\n";
print "</body></html>\n";
exit;
}
The HTML:
<HTML>
<HEAD>
<TITLE> CGI Mail Test </TITLE>
</HEAD>
<BODY>
<form action="mail.cgi" method="POST">
Your Name: <input type="text" name="name">
Email Address: <input type="text" name="email">
Age: <input type="text" name="age">
Favorite Color: <input type="text" name="favorite_color">
<input type="submit" value="Send">
<input type="reset" value="Clear Form">
</form>
</BODY>
</HTML>
Any thoughts or ideas?