View Full Version : Problem with form posting script

04-19-2010, 03:10 PM
The script I am using is supposed to take a simple HTML form and e-mail me the contents at apesquaregraphics@gmail.com, and then produce a "Thank You" confirmation page. When I post the form, I can't figure out how to get it to actually send me the email. It created the Thank You page, but doesn't send the email. Please help! Here is the script:

use CGI::Carp qw(fatalsToBrowser);

# The following accepts the data from the form and splits it into its component parts


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;

# Then sends the email

open (MESSAGE,"| /usr/sbin/sendmail -t");

print MESSAGE "To: apesquaregraphics\@gmail.com\n"; # Don't forget to escape this @ symbol!
print MESSAGE "From: " . $FORM{name} . ", reader\n";
print MESSAGE "Reply-to: " . $FORM{email} . "(" . $FORM{name} . ")\n";

print MESSAGE "Subject: Inquiry from $FORM{name} \n\n";

print MESSAGE "$FORM{name} wrote:\n\n";
print MESSAGE "Comment: $FORM{comment}\n\n";
print MESSAGE "Sent by: $FORM{name} ($FORM{email}).\n";

close (MESSAGE);

&thank_you; #method call

#The code then goes on to generate the thank-you page

sub thank_you {

print "Content-type: text/html\n\n";

print <<EndStart;

<title>Thanks for your inquiry!</title></head>
<body bgcolor="#ffffff" link="#000000" alink="#000000"
<center><table width="624" valign="top" border="0" cellpadding="0"
cellspacing="5"><tr><td valign="top" bgcolor="white"><img src="apesquarelogo.jpg"
width="312" height="440" alt="ApeSquare Graphic Design"></td><td width="312"
bgcolor="#B7FF29" valign="top"><table border="0" cellpadding="0" cellspacing="0"
width="100%"><tr height="121" bgcolor="white"><td>&nbsp;</td></tr>
<tr bgcolor="#B7FF29"><td valign="top">
<img src="thankyou.jpg" alt="Thank You" width="312" height="50"><br>
<table border="0" width="100%" cellpadding="20" cellspacing="0">
<tr><td valign="top"><font face="georgia" size="2" color="#000000">We will process your inquiry and get back to you as soon as possible.<br>
<a href="index.html">< Back to Previous Page</td></tr></table>


print "<p></p>\n";
print "<blockquote><em>$FORM{comment}</em></blockquote>\n\n";

print <<EndHTML;




04-20-2010, 04:22 PM
Try the formmail script from the NMS project.

04-20-2010, 05:20 PM
The page below might be useful

cgi form mail example (http://www.html-form-guide.com/form-mail/cgi-form-mail.html)