Sarcalogus Posted June 27, 2012 Share Posted June 27, 2012 Hi there, I have a huge problem with one of my PHP forms that i put on a website. I'm reasonably new to PHP so as much help as possible is appreciated. This is the code that i have: <?php if(isset($_POST['email'])) { // CHANGE THE TWO LINES BELOW $email_to = "admin@randburgfleamarket.co.za"; $email_subject = "Feedback from the Randburg Flea Market website"; 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.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['surname']) || !isset($_POST['telephone']) || !isset($_POST['email']) || !isset($_POST['subject']) || !isset($_POST['message'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $surname = $_POST['surname']; // required $telephone = $_POST['telephone']; // not required $email_from = $_POST['email']; // required $subject = $_POST['subject']; // required $message = $_POST['message']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$surname)) { $error_message .= 'The Surname you entered does not appear to be valid.<br />'; } if(strlen($message) < 2) { $error_message .= 'The Message you entered do not appear to be valid.<br />'; } if(strlen($subject) < 2) { $error_message .= 'The Subject you entered do not appear to be valid.<br />'; } 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 .= "Name: ".clean_string($first_name)."\n"; $email_message .= "Surname: ".clean_string($surname)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Subject: ".clean_string($subject)."\n"; $email_message .= "Message: ".clean_string($message)."\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); ?> <!-- place your own success html below --> Thank you for contacting us. We will be in touch with you very soon. » Go back to <a href="../index.html">Home page</a> <?php } die(); ?> but somehow when i click on the Submit button, the result is as follows: "; echo $error." "; echo "Please go back and fix these errors. "; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['surname']) || !isset($_POST['telephone']) || !isset($_POST['email']) || !isset($_POST['subject']) || !isset($_POST['message'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $surname = $_POST['surname']; // required $telephone = $_POST['telephone']; // not required $email_from = $_POST['email']; // required $subject = $_POST['subject']; // required $message = $_POST['message']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid. '; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The Name you entered does not appear to be valid. '; } if(!preg_match($string_exp,$surname)) { $error_message .= 'The Surname you entered does not appear to be valid. '; } if(strlen($message) < 2) { $error_message .= 'The Message you entered do not appear to be valid. '; } if(strlen($subject) < 2) { $error_message .= 'The Subject you entered do 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 .= "Name: ".clean_string($first_name)."\n"; $email_message .= "Surname: ".clean_string($surname)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Subject: ".clean_string($subject)."\n"; $email_message .= "Message: ".clean_string($message)."\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. ? Go back to Home page Please help, i am desperate and have been going over this for the last 4 hours to try and figure out the problem. The website is www.randburgfleamarket.co.za/contact/index.html Thanking you so much in advance. Quote Link to comment https://forums.phpfreaks.com/topic/264873-huge-php-code-error-submit-not-working-correctly/ Share on other sites More sharing options...
marcus Posted June 27, 2012 Share Posted June 27, 2012 Looks like you have a MIME type problem. It's not recognizing the .php file extension as a PHP document. Quote Link to comment https://forums.phpfreaks.com/topic/264873-huge-php-code-error-submit-not-working-correctly/#findComment-1357399 Share on other sites More sharing options...
Sarcalogus Posted June 28, 2012 Author Share Posted June 28, 2012 Ok so how do i fix this. Is it a problem with my IS, that they don't support PHP files or do i need to rename my php file? Quote Link to comment https://forums.phpfreaks.com/topic/264873-huge-php-code-error-submit-not-working-correctly/#findComment-1357628 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.