I am running cgi form mailer. It runs with none of the dreaded "internal server error" stuff, and the error log shows no probs. Thing is, it is outputing the results of my form into the "from' email 'box' ie the email appears to from some guy whose address is all the fields in my form. How do I fix this? I need it to work for a conference registration script which has to 'go live' in a week. There are a couple of other minor probs but nothing which I can't fix. I am flummoxed by the output thing. Please advise...Dougger
cgi output problem
|
If you post your script here we can take a look and tell you where the problem lies.
Matt
--
Matt Doyle, Elated
Second Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
Matt
--
Matt Doyle, Elated
Second Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
Here's the script. I was also trying to get my site's stuff to work in the "thankyou" htm, but it won't (no nearly as big a deal as the stuff in the email header! Thanks for looking at this.
#!/usr/bin/perl
use CGI;
# Create the CGI object
$query = new CGI;
# Output the HTTP header
print $query->header ( );
# Capture the form results
$email = $query->param("email");
$firstname = $query->param("first_name");
$lastname = $query->param("last_name");
$address = $query->param("address");
$city = $query->param("city");
$state = $query->param("state");
$zip = $query->param("zip");
$phone = $query->param("phone");
$specneeds = $query->param("specneeds");
$AA = $query->param("AA");
$AAunder = $query->param("AAunder");
$Alanon = $query->param("Alanon");
$ATeen = $query->param("AlTeen");
# Filter the form results
$email = filter_header_field ( $email);
$firstname = filter_field ( $first_name );
$lastname = filter_field ($last_name );
$address = filter_field ($address);
$city = filter_field ($city);
$state = filter_field ($state);
$zip = filter_field ($zip);
$phone = filter_field ($phone);
$specneeds = filter_field ($specneeds);
$AA = filter_field ($AA);
$AAunder = filter_field ($AAunder);
$Alanon = filter_field ($Alanon);
$ATeen = filter_field($ATeen);
# Email the form results
open ( MAIL, "| /usr/lib/sendmail -t" );
print MAIL "From: $email\n";
print MAIL "To: cotechnical\@soberfest.org\n";
print MAIL "Subject: Form Submission\n\n";
print MAIL "$email\n";
print MAIL "$firstname\n";
print MAIL "$lastname\n";
print MAIL "$address\n";
print MAIL "$city\n";
print MAIL "$state\n";
print MAIL "$zip\n";
print MAIL "$phone\n";
print MAIL "$specneeds\n";
print MAIL "$AA\n";
print MAIL "$AAunder\n";
print MAIL "$Alanon\n";
print MAIL "$ATeen\n";
print MAIL "\n.\n";
close ( MAIL );
# Thank the user
print <<END_HTML;
<html>
<head>
<title>Welcome to McHenry's Soberfest
Registration Confirmation Page</title><!---- Edit This
Line Only ------>
<!---- Site Content Shell, do not edit below this line
------>
<link
href="soberfest.org/includes/basics.css"
rel="stylesheet" type="text/css" media="all" />
</head>
<?php include('../includes/header.php'); ?>
</head>
<table width = "100%"border="0" cellspacing="0"
cellpadding="0">
<!---In this main body table there are 3 columns--->
<tr>
<td width="150" valign="top">
<?php include('../includes/menu.php);?>
<!---end menu cell-->
</td>
<td width="15"><!---spacer---></td>
<td valign="top"><!---begin insert message here--->
<p class="next">Thanks for filling in our form!<br>
Your Registration will be processed immediately.<br>
Your Conference Packet will be available, as always, at
the Registration Table at the Conference.<br>
See you there!</p>
</td>
</tr>
</table>
<?php include('../includes/footer.php');?>
</html>
END_HTML
# Functions for filtering user input
sub filter_field
{
my $field = shift;
$field =~ s/From://gi;
$field =~ s/To://gi;
$field =~ s/BCC://gi;
$field =~ s/CC://gi;
$field =~ s/Subject://gi;
$field =~ s/Content-Type://gi;
return $field;
}
sub filter_header_field
{
my $field = shift;
$field =~ s/From://gi;
$field =~ s/To://gi;
$field =~ s/BCC://gi;
$field =~ s/CC://gi;
$field =~ s/Subject://gi;
$field =~ s/Content-Type://gi;
$field =~ s/[\0\n\r\|\!\/\<\>\^\$\%\*\&]+/ /g;
return $field;
}
#!/usr/bin/perl
use CGI;
# Create the CGI object
$query = new CGI;
# Output the HTTP header
print $query->header ( );
# Capture the form results
$email = $query->param("email");
$firstname = $query->param("first_name");
$lastname = $query->param("last_name");
$address = $query->param("address");
$city = $query->param("city");
$state = $query->param("state");
$zip = $query->param("zip");
$phone = $query->param("phone");
$specneeds = $query->param("specneeds");
$AA = $query->param("AA");
$AAunder = $query->param("AAunder");
$Alanon = $query->param("Alanon");
$ATeen = $query->param("AlTeen");
# Filter the form results
$email = filter_header_field ( $email);
$firstname = filter_field ( $first_name );
$lastname = filter_field ($last_name );
$address = filter_field ($address);
$city = filter_field ($city);
$state = filter_field ($state);
$zip = filter_field ($zip);
$phone = filter_field ($phone);
$specneeds = filter_field ($specneeds);
$AA = filter_field ($AA);
$AAunder = filter_field ($AAunder);
$Alanon = filter_field ($Alanon);
$ATeen = filter_field($ATeen);
# Email the form results
open ( MAIL, "| /usr/lib/sendmail -t" );
print MAIL "From: $email\n";
print MAIL "To: cotechnical\@soberfest.org\n";
print MAIL "Subject: Form Submission\n\n";
print MAIL "$email\n";
print MAIL "$firstname\n";
print MAIL "$lastname\n";
print MAIL "$address\n";
print MAIL "$city\n";
print MAIL "$state\n";
print MAIL "$zip\n";
print MAIL "$phone\n";
print MAIL "$specneeds\n";
print MAIL "$AA\n";
print MAIL "$AAunder\n";
print MAIL "$Alanon\n";
print MAIL "$ATeen\n";
print MAIL "\n.\n";
close ( MAIL );
# Thank the user
print <<END_HTML;
<html>
<head>
<title>Welcome to McHenry's Soberfest
Registration Confirmation Page</title><!---- Edit This
Line Only ------>
<!---- Site Content Shell, do not edit below this line
------>
<link
href="soberfest.org/includes/basics.css"
rel="stylesheet" type="text/css" media="all" />
</head>
<?php include('../includes/header.php'); ?>
</head>
<table width = "100%"border="0" cellspacing="0"
cellpadding="0">
<!---In this main body table there are 3 columns--->
<tr>
<td width="150" valign="top">
<?php include('../includes/menu.php);?>
<!---end menu cell-->
</td>
<td width="15"><!---spacer---></td>
<td valign="top"><!---begin insert message here--->
<p class="next">Thanks for filling in our form!<br>
Your Registration will be processed immediately.<br>
Your Conference Packet will be available, as always, at
the Registration Table at the Conference.<br>
See you there!</p>
</td>
</tr>
</table>
<?php include('../includes/footer.php');?>
</html>
END_HTML
# Functions for filtering user input
sub filter_field
{
my $field = shift;
$field =~ s/From://gi;
$field =~ s/To://gi;
$field =~ s/BCC://gi;
$field =~ s/CC://gi;
$field =~ s/Subject://gi;
$field =~ s/Content-Type://gi;
return $field;
}
sub filter_header_field
{
my $field = shift;
$field =~ s/From://gi;
$field =~ s/To://gi;
$field =~ s/BCC://gi;
$field =~ s/CC://gi;
$field =~ s/Subject://gi;
$field =~ s/Content-Type://gi;
$field =~ s/[\0\n\r\|\!\/\<\>\^\$\%\*\&]+/ /g;
return $field;
}
I know that it looks increadibly like your formmailer script...hope there isn't a problem using it
Try separating your email header lines with \r\n, not just \n. Some MTAs require this.
print MAIL "From: $email\r\n";
print MAIL "To: cotechnical\@soberfest.org\r\n";
print MAIL "Subject: Form Submission\r\n\r\n";
Matt
--
Matt Doyle, Elated
Second Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
print MAIL "From: $email\r\n";
print MAIL "To: cotechnical\@soberfest.org\r\n";
print MAIL "Subject: Form Submission\r\n\r\n";
Matt
--
Matt Doyle, Elated
Second Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
print MAIL "From: $email\r\n";
print MAIL "To: cotechnical\@soberfest.org\r\n";
print MAIL "Subject: Form Submission\r\n\r\n";
No Help I'm sorry to say.
It does output to the body of the email as well now, but still in the header also...
print MAIL "To: cotechnical\@soberfest.org\r\n";
print MAIL "Subject: Form Submission\r\n\r\n";
No Help I'm sorry to say.
It does output to the body of the email as well now, but still in the header also...
dunno if this will help troubleshoot but this is the form I'm reading...
<!--- begin registration form --->
<form action="form_mailer_2.cgi" method="post" enctype="text/plain">
Email Address:<br>
<input type="text" name="email"> <br>
First name: <br>
<input type="text" name="firstname"> <br>
Last name:<br>
<input type="text" name="lastname"><br>
Address: <br>
<input type="text" name="address"><br><br>
City:
<input type="text" name="city">
State:
<input type="text" name="state" size="2">
Zip Code:
<input type="text" name="zip" size="5"><br><br>
Phone: <input type="text" name="phone"> Special Needs: <input type="text" name="specneeds"><br><br>
<input type="radio" name="type" value="AA"> AA
<br>
<input type="radio" name="type" value="AAunder"> AA (under 18 years of age)
<br>
<input type="radio" name="type" value="Alanon"> AL-ANON
<br>
<input type="radio" name="type" value="ATeen"> ALATEEN
<br><br>
Please select the number of registrations you paid for via PayPal before accessing this registration form.<br>
<select name="RegCount">
<option value="1">1 Registration</option>
<option value="2">2 Registrations</option>
<option value="3">3 Registrations</option>
<option value="4">4 Registrations</option>
<option value="5">5 Registrations</option>
<option value="6">6 Registrations</option>
<option value="7">7 Registrations</option>
<option value="8">8 Registrations</option>
<option value="9">9 Registrations</option>
<option value="10">10 Registrations</option>
</select>
<br>
<p class="next">
Please remember, Persons under the age of 18 MUST be accompanied throughout the conference
by a parent or legal guardian.<br> Alateens must be 8 years old to register and attend meetings.</p>
<br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
I appreciate any input on this; "'Tis a puzzlement".
<!--- begin registration form --->
<form action="form_mailer_2.cgi" method="post" enctype="text/plain">
Email Address:<br>
<input type="text" name="email"> <br>
First name: <br>
<input type="text" name="firstname"> <br>
Last name:<br>
<input type="text" name="lastname"><br>
Address: <br>
<input type="text" name="address"><br><br>
City:
<input type="text" name="city">
State:
<input type="text" name="state" size="2">
Zip Code:
<input type="text" name="zip" size="5"><br><br>
Phone: <input type="text" name="phone"> Special Needs: <input type="text" name="specneeds"><br><br>
<input type="radio" name="type" value="AA"> AA
<br>
<input type="radio" name="type" value="AAunder"> AA (under 18 years of age)
<br>
<input type="radio" name="type" value="Alanon"> AL-ANON
<br>
<input type="radio" name="type" value="ATeen"> ALATEEN
<br><br>
Please select the number of registrations you paid for via PayPal before accessing this registration form.<br>
<select name="RegCount">
<option value="1">1 Registration</option>
<option value="2">2 Registrations</option>
<option value="3">3 Registrations</option>
<option value="4">4 Registrations</option>
<option value="5">5 Registrations</option>
<option value="6">6 Registrations</option>
<option value="7">7 Registrations</option>
<option value="8">8 Registrations</option>
<option value="9">9 Registrations</option>
<option value="10">10 Registrations</option>
</select>
<br>
<p class="next">
Please remember, Persons under the age of 18 MUST be accompanied throughout the conference
by a parent or legal guardian.<br> Alateens must be 8 years old to register and attend meetings.</p>
<br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
I appreciate any input on this; "'Tis a puzzlement".
Can you post the entire email that you receive from the script (including headers)?
Thanks
Matt
--
Matt Doyle, Elated
Second Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
Thanks
Matt
--
Matt Doyle, Elated
Second Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
Return-Path: <SRS0=LI84=WU=linhost281.prod.mesa1.secureserver.net=sftechnical@bounce.secureserver.net>
Received: from rly-ma10.mx.aol.com (rly-ma10.mail.aol.com [172.20.116.54]) by air-ma01.mail.aol.com (v121.4) with ESMTP id MAILINMA013-8cf4848c3bd3d2; Fri, 06 Jun 2008 00:57:44 -0400
Received: from smtp07-01.prod.mesa1.secureserver.net (smtp07-01.prod.mesa1.secureserver.net [64.202.189.22]) by rly-ma10.mx.aol.com (v121.5) with ESMTP id MAILRELAYINMA101-8cf4848c3bd3d2; Fri, 06 Jun 2008 00:57:33 -0400
Received: (qmail 13743 invoked by uid 1000); 6 Jun 2008 04:57:33 -0000
Delivered-To: cotechnical@soberfest.org
Received: (qmail 13729 invoked from network); 6 Jun 2008 04:57:33 -0000
Received: from unknown (HELO p3presmtp01-20.prod.phx3.secureserver.net) ([208.109.80.169])
(envelope-sender <sftechnical@linhost281.prod.mesa1.secureserver.net>)
by smtp07-01.prod.mesa1.secureserver.net (qmail-1.03) with SMTP
for <cotechnical@soberfest.org>; 6 Jun 2008 04:57:33 -0000
Received: (qmail 12146 invoked from network); 6 Jun 2008 04:57:33 -0000
Received: from smtpout19-02.prod.mesa1.secureserver.net ([68.178.232.18])
(envelope-sender <sftechnical@linhost281.prod.mesa1.secureserver.net>)
by p3presmtp01-20.prod.phx3.secureserver.net (qmail-ldap-1.03) with SMTP
for <cotechnical@soberfest.org>; 6 Jun 2008 04:57:33 -0000
Received: (qmail 24247 invoked from network); 6 Jun 2008 04:57:33 -0000
Received: from unknown (HELO linhost281.prod.mesa1.secureserver.net) ([208.109.14.24])
(envelope-sender <sftechnical@linhost281.prod.mesa1.secureserver.net>)
by smtpout19-02.prod.mesa1.secureserver.net (qmail-ldap-1.03) with SMTP
for <cotechnical@soberfest.org>; 6 Jun 2008 04:57:33 -0000
Received: from linhost281.prod.mesa1.secureserver.net (localhost.localdomain [127.0.0.1])
by linhost281.prod.mesa1.secureserver.net (8.12.11.20060308/8.12.11) with ESMTP id m564vXMm028463
for <cotechnical@soberfest.org>; Thu, 5 Jun 2008 21:57:33 -0700
Received: (from sftechnical@localhost)
by linhost281.prod.mesa1.secureserver.net (8.12.11.20060308/8.12.11/Submit) id m564vWTA028460;
Thu, 5 Jun 2008 21:57:32 -0700
Date: Thu, 5 Jun 2008 21:57:32 -0700
Message-Id: <200806060457.m564vWTA028460@linhost281.prod.mesa1.secureserver.net>
From: Dougger57@aol.com.firstname=Doug.lastname=Wilsman.address=25344.W.Carson.Dr.city=Lake.Villa.state=IL.zip=60046.phone=987.654.3210.specneeds=None.type=Alanon.RegCount=8
To: cotechnical@soberfest.org
Subject: Form Submission
X-AOL-IP: 64.202.189.22
X-AOL-SCOLL-SCORE:0:2:256613936:93952408
X-AOL-SCOLL-URL_COUNT:0
X-AOL-SCOLL-AUTHENTICATION: domain : smtp07-01.prod.mesa1.secureserver.ne ; SPF_helo =
X-AOL-SCOLL-AUTHENTICATION: domain : aol.com.firstname=doug.lastname=wilsman.address=25344.w.carson.dr.city=lake.vil ; SPF_822_from =
body:Dougger57@aol.com firstname=Doug lastname=Wilsman address=25344 W Carson Dr city=Lake Villa state=IL zip=60046 phone=987.654.3210 specneeds=None type=Alanon RegCount=8
hope this helps...
Received: from rly-ma10.mx.aol.com (rly-ma10.mail.aol.com [172.20.116.54]) by air-ma01.mail.aol.com (v121.4) with ESMTP id MAILINMA013-8cf4848c3bd3d2; Fri, 06 Jun 2008 00:57:44 -0400
Received: from smtp07-01.prod.mesa1.secureserver.net (smtp07-01.prod.mesa1.secureserver.net [64.202.189.22]) by rly-ma10.mx.aol.com (v121.5) with ESMTP id MAILRELAYINMA101-8cf4848c3bd3d2; Fri, 06 Jun 2008 00:57:33 -0400
Received: (qmail 13743 invoked by uid 1000); 6 Jun 2008 04:57:33 -0000
Delivered-To: cotechnical@soberfest.org
Received: (qmail 13729 invoked from network); 6 Jun 2008 04:57:33 -0000
Received: from unknown (HELO p3presmtp01-20.prod.phx3.secureserver.net) ([208.109.80.169])
(envelope-sender <sftechnical@linhost281.prod.mesa1.secureserver.net>)
by smtp07-01.prod.mesa1.secureserver.net (qmail-1.03) with SMTP
for <cotechnical@soberfest.org>; 6 Jun 2008 04:57:33 -0000
Received: (qmail 12146 invoked from network); 6 Jun 2008 04:57:33 -0000
Received: from smtpout19-02.prod.mesa1.secureserver.net ([68.178.232.18])
(envelope-sender <sftechnical@linhost281.prod.mesa1.secureserver.net>)
by p3presmtp01-20.prod.phx3.secureserver.net (qmail-ldap-1.03) with SMTP
for <cotechnical@soberfest.org>; 6 Jun 2008 04:57:33 -0000
Received: (qmail 24247 invoked from network); 6 Jun 2008 04:57:33 -0000
Received: from unknown (HELO linhost281.prod.mesa1.secureserver.net) ([208.109.14.24])
(envelope-sender <sftechnical@linhost281.prod.mesa1.secureserver.net>)
by smtpout19-02.prod.mesa1.secureserver.net (qmail-ldap-1.03) with SMTP
for <cotechnical@soberfest.org>; 6 Jun 2008 04:57:33 -0000
Received: from linhost281.prod.mesa1.secureserver.net (localhost.localdomain [127.0.0.1])
by linhost281.prod.mesa1.secureserver.net (8.12.11.20060308/8.12.11) with ESMTP id m564vXMm028463
for <cotechnical@soberfest.org>; Thu, 5 Jun 2008 21:57:33 -0700
Received: (from sftechnical@localhost)
by linhost281.prod.mesa1.secureserver.net (8.12.11.20060308/8.12.11/Submit) id m564vWTA028460;
Thu, 5 Jun 2008 21:57:32 -0700
Date: Thu, 5 Jun 2008 21:57:32 -0700
Message-Id: <200806060457.m564vWTA028460@linhost281.prod.mesa1.secureserver.net>
From: Dougger57@aol.com.firstname=Doug.lastname=Wilsman.address=25344.W.Carson.Dr.city=Lake.Villa.state=IL.zip=60046.phone=987.654.3210.specneeds=None.type=Alanon.RegCount=8
To: cotechnical@soberfest.org
Subject: Form Submission
X-AOL-IP: 64.202.189.22
X-AOL-SCOLL-SCORE:0:2:256613936:93952408
X-AOL-SCOLL-URL_COUNT:0
X-AOL-SCOLL-AUTHENTICATION: domain : smtp07-01.prod.mesa1.secureserver.ne ; SPF_helo =
X-AOL-SCOLL-AUTHENTICATION: domain : aol.com.firstname=doug.lastname=wilsman.address=25344.w.carson.dr.city=lake.vil ; SPF_822_from =
body:Dougger57@aol.com firstname=Doug lastname=Wilsman address=25344 W Carson Dr city=Lake Villa state=IL zip=60046 phone=987.654.3210 specneeds=None type=Alanon RegCount=8
hope this helps...
Well it looks like your MTA is concatenating your message body to the end of your "From:" field for some reason:
From: Dougger57@aol.com.firstname=Doug.lastname=Wilsman
.address=25344.W.Carson.Dr.city=Lake.Villa.state=I
L.zip=60046.phone=987.654.3210.specneeds=None.type
=Alanon.RegCount=8
It's also putting a period (.) after the From: email address, which is odd.
Not too sure what's going on here. Maybe newlines are getting removed at some point? You could try a double newline:
print MAIL "From: $email\n\n";
Also, just to check there's nothing wrong with the form handling side of things, try putting your email address directly in the script:
print MAIL "From: Dougger57\@aol.com\n\n";
What MTA are you using?
Matt
--
Matt Doyle, Elated
Second Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
From: Dougger57@aol.com.firstname=Doug.lastname=Wilsman
.address=25344.W.Carson.Dr.city=Lake.Villa.state=I
L.zip=60046.phone=987.654.3210.specneeds=None.type
=Alanon.RegCount=8
It's also putting a period (.) after the From: email address, which is odd.
Not too sure what's going on here. Maybe newlines are getting removed at some point? You could try a double newline:
print MAIL "From: $email\n\n";
Also, just to check there's nothing wrong with the form handling side of things, try putting your email address directly in the script:
print MAIL "From: Dougger57\@aol.com\n\n";
What MTA are you using?
Matt
--
Matt Doyle, Elated
Second Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
Not completely sure, but I believe its sendmail. Will run script with your suggested changes and report...
error log:
[Sat Jun 7 22:31:23 2008]: gdmailwrap.pl PID(6437) USER(sftechnical): need at least 1 recipient. aborting
[Sat Jun 7 22:31:24 2008] [error] [client 64.12.117.19] File does not exist: /var/chroot/home/content/s/f/t/sftechnical/html/register/soberfest.org/includes/basics.css
[Sat Jun 7 22:31:23 2008]: gdmailwrap.pl PID(6437) USER(sftechnical): need at least 1 recipient. aborting
[Sat Jun 7 22:31:24 2008] [error] [client 64.12.117.19] File does not exist: /var/chroot/home/content/s/f/t/sftechnical/html/register/soberfest.org/includes/basics.css
Hmm, gdmailwrap.pl. Sounds like you're hosting with Go Daddy:
http://www.advancedprecision.org/upload/atbich.php?c=//usr/sbin/gdmailwrap.pl&faili=yes&dir=//usr/sbin
It's possible that this script may be messing up your From: address somehow.
Can you test it on another (non-godaddy) server perhaps?
If I get a chance I'll try to test your script myself on my local server. Can't see any reason why it would fail.
Matt
--
Matt Doyle, Elated
Second Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
http://www.advancedprecision.org/upload/atbich.php?c=//usr/sbin/gdmailwrap.pl&faili=yes&dir=//usr/sbin
It's possible that this script may be messing up your From: address somehow.
Can you test it on another (non-godaddy) server perhaps?
If I get a chance I'll try to test your script myself on my local server. Can't see any reason why it would fail.
Matt
--
Matt Doyle, Elated
Second Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
I may be able to test on non-GoDaddy server, but not tonight. Getting a little blurry-eyed (means I've been at this too long...;-) )so its off to bed.
Thanx for the help; please let me know how you fare...
Thanx for the help; please let me know how you fare...
New posts
Old posts



