Form help
Date: 02/14/06
(WebDesign) Keywords: php, browser
This is driving me nuts! I've created a form.. using the same technique that I've created hundreds of other forms with, and for some reason I cannot get this form to send the email! I need a fresh pair of eyes. Anyone that would like to take a look and tell me if you see something wrong with the coding, I would REALLY appreciate it!
The form:
< form method="post" action="../php_uploads/comment.php">
< font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">
< input type="hidden" name="subject" value="Perfect Pools - Comment Form">
Name: < input type="text" name="Name" size="30">
Address: < input type="text" name="Address" size="30">
City: < input type="text" name="City" size="30"> State: < input type="text" name="State" size="5">
Zip: < input type="text" name="Zip" size="20">
Daytime Phone: < input type="text" name="DaytimePhone" size="20">
Evening Phone: < input type="text" name="EveningPhone" size="20">
Email: < input type="text" name="Email" size="30">
Comments: < textarea name="Comments" rows="5" cols="30">
< input name="submit" type="submit" value="Submit Comments"> < input name="reset" type="reset" value="Clear Comments">
Email script:
< ?php
$recipient = 'brandi@wikedawsum.com';
$subject = 'Perfect Pools - Comments Form';
$form_url = 'http://perfectpools.wikedawsum.com/pages/comment.php';
$msg .= "---------------\n";
$msg .= "$subject\n";
$msg .= "---------------\n\n";
$msg .= "Name: $_POST[Name]\n";
$msg .= "Address: $_POST[Address]\n";
$msg .= "City: $_POST[City]\n";
$msg .= "State: $_POST[State]\n";
$msg .= "Zip: $_POST[Zip]\n";
$msg .= "Daytime Phone: $_POST[DaytimePhone]\n";
$msg .= "Evening Phone: $_POST[EveningPhone]\n";
$msg .= "Email: $_POST[email]\n";
$msg .= "Comments: $_POST[Comments]\n";
$req1 ="$Name";
$req2 ="$Email";
$req3 ="$DaytimePhone";
$error_required = '< p align="center">< strong>< font color="#000000" size="4" face="Geneva, Arial, Helvetica, sans-serif">It appears you forgot to enter either your name, email, or a daytime phone number. Please press the BACK button in your browser and try again.';
$error_email = '< p align="center">< strong>< font color="#000000" size="4" face="Geneva, Arial, Helvetica, sans-serif">Oops, it appears that the email address you filled in is not a valid one. Please press the back button on your browser and try again. Please check carefully that you filled in all information in the right fields!';
$success_message = '< p align="center">< strong>< font color="#000000" size="4" face="Geneva, Arial, Helvetica, sans-serif">Your information was submitted successfully! Someone will contact you within the next few business days. Please call our main office if you have any questions.
< font color="#000000" size="3" face="Geneva, Arial, helvetical, sans-serif">Return to the Home page.';
if ($header ==""){
$use_headers ='0';
$header = '';
} else {$use_headers ='1';}
if ($footer ==""){
$use_footers ='0';
$footer = '';
} else {$use_footers ='1';}
function is_valid_email ($address) {
return (preg_match(
'/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+'.
'@'.
'([-0-9A-Z]+\.)+' .
'([0-9A-Z]){2,4}$/i',
trim($address)));
}
function is_valid_email_eregi ($address) {
return (eregi(
'^[-!#$%&\'*+\\./0-9=?A-Z^_`{|}~]+'.
'@'.
'([-0-9A-Z]+\.)+' .
'([0-9A-Z]){2,4}$',
trim($address)));
}
if (!isset($req1) || !isset($req2) || !isset($req3)) {
header( "Location: $form_url" ); }
elseif (empty($req1) || empty($req2) || empty($req3)) {
if ($use_headers =="0"){
echo "$header";
} else { include ("$header"); }
?>
< h2>< font color="#000000">Error
=$error_required?>
if ($use_footers =="0"){
echo "$footer";
} else { include ("$footer"); }
}
else {
$f_email = $_POST[email];
$f_email = strtolower(trim($f_email));
if (is_valid_email($f_email)) {
$msg .= "\n\n---------------\n";
$msg .= "NL-PHPMail v1.5 - http://codegrrl.com/\n";
$msg .= "---------------\n\n";
$mailheaders = "MIME-Version: 1.0 \n";
$mailheaders .= "Content-type: text/plain; charset=iso-8859-1 \n";
$mailheaders .= "From: \"$_POST[email]\" <$_POST[email]> \n";
$mailheaders .= "Reply-To: \"$_POST[email]\" <$_POST[email]> \n";
$mailheaders .= "X-Priority: 3 \n";
$mailheaders .= "X-MSMail-Priority: High \n";
$mailheaders .= "X-Mailer: PHP4";
mail($recipient, $subject, $msg, $mailheaders);
if ($use_headers =="0"){
echo "$header";
} else { include ("$header"); }
?>
< h2>< font color="#000000">Thank You, =$name?>
=$success_message?>
if ($use_footers =="0"){
echo "$footer";
} else { include ("$footer"); }
} else {
if ($use_headers =="0"){
echo "$header";
} else { include ("$header"); }
?>
< h2>< font color="#000000">Error
=$error_email?>
if ($use_footers =="0"){
echo "$footer";
} else { include ("$footer"); }
} } ? >
Thank you all in advance!
Update: I know the code is pointing to the form correctly because when I fill it out and hit submit I get the error message about one of my required fields not being filled out. However, the fields ARE filled out correctly. Not sure what the problem is.
Source: http://community.livejournal.com/webdesign/1061027.html