timothyarden Posted October 6, 2012 Share Posted October 6, 2012 Hi PHP Freaks, I have written a php email form and then this code behind it. When I run it comes up with the error page however all inputs are filled in and valid. Here is my code: <?php //variables from form $firstname = ucwords(strtolower($_POST['firstname'])); $lastname = ucwords(strtolower($_POST['lastname'])); $client_email_address = $_POST['email_address']; $subject = $_POST['subject']; $message = wordwrap($_POST['message'], 150, '<br />'); $fullname = $firstname.' '.$lastname; //error pages $email_successful_page = 'mail_successful.php'; //create mail_successful.php; $email_failed_page = 'delivery_failed.php'; //create delivery_failed.php; //create emailform.php (and in it the ability to read the error from this script and tell the user //set date date_default_timezone_set('Australia/NSW'); //email 1 is sent to the scd admin email $email_1_recipient_address = 'joshua.paduch@gmail.com'; //'systemadministrator@shellharbourcitydental.com.au'; $email_1_subject = 'Email sent to '.$dentist_name.' from '.$client_email.' regarding '.$subject; $email_1_message = '<html>\n\t<body>\n\t\t<img src=\"emailheader.jpg\" width="" height="" style="float:center;"/>\n\t\t'; $email_1_message .= '\n\t\t<h1>Hi System Administrator, </h1>'; $email_1_message .= '\n\t\t<br /><p>For records, </p>'; //$email_1_message .= ''; //$email_1_message .= ''; $email_1_headers = "From: autoresponder@shellharbourcitydental.com.au \r\n"; $email_1_headers .= "Reply-To: donotreply@shellharbourcitydental.com.au \r\n"; $email_1_headers .= "X-Mailer: PHP/".phpversion()." \r\n"; $email_1_headers .= "To: joshua.paduch@gmail.com \r\n"; $email_1_headers .= "Content-type: text/html; charset=UTF-8 \r\n"; $email_1_headers .= "MIME-Version: 1.0 \r\n"; //$email_1_headers .= " \r\n"; //email 2 is sent to the intended dentist / practitioner $email_2_recipient_address = 'joshua.paduch@gmail.com'; //'info@shellharbourcitydental.com.au'; $email_2_subject = $subject; $email_2_message = 'message'; //$email_2_message .= ''; //$email_2_message .= ''; $email_2_headers = "From: autoresponder@shellharbourcitydental.com.au \r\n"; $email_2_headers .= "Reply-To: donotreply@shellharbourcitydental.com.au \r\n"; $email_2_headers .= "X-Mailer: PHP/".phpversion()." \r\n"; $email_2_headers .= "To: joshua.paduch@gmail.com \r\n"; $email_2_headers .= "Content-type: text/html; charset=UTF-8 \r\n"; $email_2_headers .= "MIME-Version: 1.0 \r\n"; //$email_2_headers .= " \r\n"; //email 3 is a confirmation email sent to the client $email_3_recipient_address = $client_email_address; $email_3_subject = 'Confirmation Email Regarding: '.$subject; $email_3_message = 'message'; //$email_3_message .= ''; //$email_3_message .= ''; $email_3_headers = "From: autoresponder@shellharbourcitydental.com.au \r\n"; $email_3_headers .= "Reply-To: donotreply@shellharbourcitydental.com.au \r\n"; $email_3_headers .= "X-Mailer: PHP/".phpversion()." \r\n"; $email_3_headers .= "To: ".$client_email." \r\n"; $email_3_headers .= "Content-type: text/html; charset=UTF-8 \r\n"; $email_3_headers .= "MIME-Version: 1.0 \r\n"; //$email_3_headers .= " \r\n"; //form validation function function form_validation($var1,$var2,$var3,$var4,$var5){ if(isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email_address']) && isset($_POST['subject']) && isset($_POST['message'])){ if(strlen($var1) < 1){ return false; $error = "firstname"; } elseif(strlen($var2) < 1){ return false; $error = "lastname"; } elseif(!filter_var($var3, FILTER_VALIDATE_EMAIL)){ return false; $error = "invalid email address"; } elseif(strlen($var4) < 1){ return false; $error = "subject"; } elseif(strlen($var5) < 1){ return false; $error = "message"; } else{ return true; } } else{ return false; } } //emailing function function email($email_1_var_1,$email_1_var_2,$email_1_var_3,$email_1_var_4,$email_2_var_1,$email_2_var_2,$email_2_var_3,$email_2_var_4,$email_3_var_1,$email_3_var_2,$email_3_var_3,$email_3_var_4){ if(!mail($email_1_var_1,$email_1_var_2,$email_1_var_3,$email_1_var_4)){ $email_error = "email 1 error"; } if(!mail($email_2_var_1,$email_2_var_2,$email_2_var_3,$email_2_var_4)){ $email_error = "email 2 error"; } if(!mail($email_3_var_1,$email_3_var_2,$email_3_var_3,$email_3_var_4)){ $email_error = "email 3 error"; } } //if form validation fails - redirect to error page - mail if(!form_validation($firstname,$lastname,$email_address,$subject,$message)){ header('Location: '.$email_failed_page.'?error='.$error); } else{ if(!email($email_1_recipient_address,$email_1_subject,$email_1_message,$email_1_headers,$email_2_recipient_address,$email_2_subject,$email_2_message,$email_2_headers,$email_3_recipient_address,$email_3_subject,$email_3_message,$email_3_headers)){ header('Location: '.$email_failed_page.'?email_error='.$email_error); } else{ header('Location: '.$email_succesful_page); } } Any advice is welcome. Thanks everyone, Timothy Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 6, 2012 Share Posted October 6, 2012 What's the error? Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 6, 2012 Share Posted October 6, 2012 Dude. http://us3.php.net/manual/en/language.types.array.php Arrays. Learn to use them. Quote Link to comment Share on other sites More sharing options...
timothyarden Posted October 6, 2012 Author Share Posted October 6, 2012 Christian - Thats the thing, it wont send the emails but there is no error - the error log is empty - the error variable is not set as all inputs were filled and valid. But it still redirected to my error page and the mail won't send can't figure it out. Thanks for the advice Jessica, will do. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 6, 2012 Share Posted October 6, 2012 I think you'll need to read up on functions as well, especially the part about "returning values". Quote Link to comment Share on other sites More sharing options...
timothyarden Posted October 8, 2012 Author Share Posted October 8, 2012 Any ideas on what the problem is? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.