View Full Version : PERL Mail Script

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:


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";


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";


<TITLE> CGI Mail Test </TITLE>

<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">

Any thoughts or ideas?

07-24-2008, 08:38 PM

Any ideas?

07-25-2008, 09:58 PM
does nobody know PERL around here? LOL

07-25-2008, 10:04 PM
I would say probably not, at least no where near the people who know php...

Any reason why you cant use php?

07-25-2008, 10:06 PM
Honestly, I guess because I tried sitting down and "learning" PHP, but couldn't quite get the hang of it. I got through arrays just fine, and then functions, and variables, but I guess I'm a little too STOOOPID to figure out how to correctly use arguments and such.

So, I started messing around with PERL and for some reason it just "clicked" much easier in my head than PHP did. So I decided I'd use it instead.

07-25-2008, 10:13 PM
ahhh ok.. Yea the exact opposite for me.. There a good chance that someone around here knows perl... but im not the one..

07-25-2008, 10:34 PM
LOL, well thanks anyhoo. Yea, "teaching" yourself everything about the different languages I would say is definitely the "hard" way to learn. I'm getting better, but MAN it's a taking a loooong time.

07-26-2008, 02:04 AM
It took me pretty good while to get where I am now...

It took me forever to understand a freakinnn function. lol

But I finally got the hang of it.. after that it was arrays... For a long time I never understood them.. But I think im inlove with them now...


07-31-2008, 03:49 PM

download (http://ebook.finedown.com)

08-01-2008, 10:40 PM

08-03-2008, 10:30 PM
I suppose I should just give up on the whole PERL mail script Idea... eh? LOL