I am attempting to use a php script to pass form data entered on a web site to me via email. It’s working except for one thing. There are two email addresses that need to be entered and neither one comes through in the email message. All the other form data come through. But the two email addresses are empty. Here is the script code. Any ideas? I’m a total rookie at this, so be gentle.
CODE:
<?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_from = "[email protected]"; $email_subject = "Tournament Entry"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below."; echo $error."
"; echo "Please go back and fix these errors.
"; die(); } // validation expected data exists if(!isset($_POST['boater_name']) || !isset($_POST['boater_address']) || !isset($_POST['boater_city']) || !isset($_POST['boater_state']) || !isset($_POST['boater_zip']) || !isset($_POST['boater_phone']) || !isset($_POST['email']) || !isset($_POST['boat']) || !isset($_POST['color']) || !isset($_POST['motor']) || !isset($_POST['hp']) || !isset($_POST['partner_address']) || !isset($_POST['partner_city']) || !isset($_POST['partner_state']) || !isset($_POST['partner_zip']) || !isset($_POST['partner_phone'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $boater_name = $_POST['boater_name']; // required $boater_address = $_POST['boater_address']; // required $boater_city = $_POST['boater_city']; // required $boater_state = $_POST['boater_state']; // required $boater_zip = $_POST['boater_zip']; // required $boater_phone = $_POST['boater_phone']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email)) { $error_message .= 'The email address you entered does not appear to be valid.
'; } $boat = $_POST['boat']; // required $color = $_POST['color']; // required $motor = $_POST['motor']; // required $hp = $_POST['hp']; // required $partner_name = $_POST['partner_name']; // required $partner_address = $_POST['partner_address']; // required $partner_city = $_POST['partner_city']; // required $partner_state = $_POST['partner_state']; // required $partner_zip = $_POST['partner_zip']; // required $partner_phone = $_POST['partner_phone']; // required $error_message = ""; $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$boater_name)) { $error_message .= 'The name you entered does not appear to be valid.
'; } if(!preg_match($string_exp,$partner_name)) { $error_message .= 'The name you entered does not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Boater: ".clean_string($boater_name)."\n"; $email_message .= "Address: ".clean_string($boater_address)."\n"; $email_message .= "City: ".clean_string($boater_city)."\n"; $email_message .= "State: ".clean_string($boater_state)."\n"; $email_message .= "Zip: ".clean_string($boater_zip)."\n"; $email_message .= "Phone: ".clean_string($boater_phone)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Boat: ".clean_string($boat)."\n"; $email_message .= "Color: ".clean_string($color)."\n"; $email_message .= "Motor: ".clean_string($motor)."\n"; $email_message .= "HP: ".clean_string($hp)."\n"; $email_message .= "Partner: ".clean_string($partner_name)."\n"; $email_message .= "Address: ".clean_string($partner_address)."\n"; $email_message .= "City: ".clean_string($partner_city)."\n"; $email_message .= "State: ".clean_string($partner_state)."\n"; $email_message .= "Zip: ".clean_string($partner_zip)."\n"; $email_message .= "Phone: ".clean_string($partner_phone)."\n"; $email_message .= "Email: ".clean_string($partner_email)."\n"; $email_message .= "Club: ".clean_string($club)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?>
Thank you for contacting us. We will be in touch with you very soon.
<?php } ?>