crispybean Posted February 21, 2013 Share Posted February 21, 2013 Hi there, After battling this problem for hours I have bitten the bullet and am asking for HELP! My contact form is not working, it was working, then wasn't...then was and now its definately not! The thankyou page is appearing when I have filled in the details and click SUBMIT- I am just not receiving the email. Here is my form HTML coding (I have highlighted the code that I think is making the form work and not work- as explained below! (file name contactus.html) <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Contact Us</title> <link href="layout.css" rel="stylesheet" type="text/css"> <link href="slider.css" rel="stylesheet" type="text/css"> <link href="fonts.css" rel="stylesheet" type="text/css"> <link href="fonts/sourcecode/stylesheet.css" rel="stylesheet" type="text/css"> <link href="fonts/umbrage/stylesheet.css" rel="stylesheet" type="text/css"> <link href="fonts/maidenorange/stylesheet.css" rel="stylesheet" type="text/css"> <link href="fonts/helvetica/stylesheet.css" rel="stylesheet" type="text/css"> <!--Internet Explorer Script start--> <script> function check(input) { if (input.value != document.getElementById('email_addr').value) { input.setCustomValidity('The two email addresses must match.'); } else { // input is valid -- reset the error message input.setCustomValidity(''); } } </script> <script> document.createElement("article"); document.createElement("footer"); document.createElement("header"); document.createElement("section"); document.createElement("nav"); </script> <!--Internet Explorer Script end--> <script type="text/javascript" src="js/jquery-1.3.1.min.js"></script> <script type="text/javascript" src="js/jquery.scrollTo.js"></script> <script> $(document).ready(function() { $('a.panel').click(function () { $('a.panel').removeClass('selected'); $(this).addClass('selected'); current = $(this); $('#wrapper').scrollTo($(this).attr('href'), 800); return false; }); $(window).resize(function () { resizePanel(); }); }); function resizePanel() { width = $(window).width(); height = $(window).height(); mask_width = width * $('.item').length; $('#debug').html(width + ' ' + height + ' ' + mask_width); $('#wrapper, .item').css({width: width, height: height}); $('#mask').css({width: mask_width, height: height}); $('#wrapper').scrollTo($('a.selected').attr('href'), 0); } </script> <style type="text/css"> body section { color: #000; } body section p { color: #000; text-align: center; } #outersection article form table { font-size: 18px; } </style> </head> <body> <!--start navigation--> <nav> <ul> <li><a href="index.html">home</a> </li> <li><a href="aboutus.html">about us</a></li> <li><a href="products.html">products</a> </li> <li><a href="demos.html">demos</a></li> <li><a href="contactus.html">contact us</a> </ul> </nav> <!--end navigation--> <!--start header--> <section> <header> <h1>Order online here</h1> </header> </section> <section id ="outersection"> <article> <form name="html_form_send" method="post" action="thankyou.html"> <table width="450px"> </tr> <tr> <td valign="top"> <label for="first_name">First Name *</label> </td> <td valign="top"> <input type="text" name="first_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="last_name">Last Name *</label> </td> <td valign="top"> <input type="text" name="last_name" maxlength="50" size="30"> </td> </tr> <tr> <td valign="top"> <label for="email">Email Address *</label> </td> <td valign="top"> <input type="text" name="email" maxlength="80" size="30"> </td> </tr> <tr> <td valign="top"> <label for="telephone">Telephone Number</label> </td> <td valign="top"> <input type="text" name="telephone" maxlength="30" size="30"> </td> </tr> <tr> <td valign="top"> <label for="comments">Products Requested*</label> </td> <td valign="top"> <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input type="submit" value="Submit"></td> </tr> </table> </form> </article> </section> <section> <p>Have any further queries or questions we can assist you with? Email us <a href="mailto:sales@xxxxxxx">HERE</a></p> </section> <!-- start small section--> <article id= "information"> <h1> Thankyou for visiting us at Autolecs.com.au</h1> </article> <!--end small section--> <!-- start footer--> <footer> <p></p> </footer> <!--end footer--> </body> </html> AND my php coding; (file name send_form_email.php) <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "sales@xxxxxxxxxx"; $email_subject = "Order Received"; 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['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // 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 First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments 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 .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\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); ?> <!-- include your own success html here --> <title>contactform</title> <h1>Thank you for your order - one of our friendly sales team will confirm your order soon</h1> Plus I have a confirmation page (file named thankyou.html) <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>THANKYOU!</title> <link href="layout.css" rel="stylesheet" type="text/css"> <link href="fonts.css" rel="stylesheet" type="text/css"> <link href="fonts/sourcecode/stylesheet.css" rel="stylesheet" type="text/css"> <link href="fonts/umbrage/stylesheet.css" rel="stylesheet" type="text/css"> <link href="fonts/maidenorange/stylesheet.css" rel="stylesheet" type="text/css"> <!--Internet Explorer Script start--> <script> document.createElement("article"); document.createElement("footer"); document.createElement("header"); document.createElement("section"); document.createElement("nav"); </script> <!--Internet Explorer Script end--> <style type="text/css"> #outersection #information h1 { color: #FF0; } </style> </head> <body> <!--start navigation--> <nav> <ul> <li><a href="index.html">home</a> </li> <li><a href="aboutus.html">about us</a></li> <li><a href="products.html">products</a> </li> <li><a href="demos.html">demos</a></li> <li><a href="contactus.html">contact us</a> </li></ul> </nav> <!--end navigation--> <!--start header--> <!--end header--> <!--start main section--> <!--end main section--> <!-- start small section--> <section id ="outersection"> <article id= "information"> <h1> </h1> <h1> </h1> <h1> </h1> <h1> </h1> <h1> </h1> <h1>Thankyou - your order has been received and</h1> <h1>you will be contacted shortly by one of our </h1> <h1>friendly sales team!</h1> </article> </section> <!--end small section--> <!-- start footer--> <footer> <p></p> </footer> <!--end footer--> </body> </html> Now, the problem (I think) lies in the highlighted row of HTML code. When I changed it to this the EMAIL worked, but the thankyou page did not appear- just basic text on a blank screen that when clicked 'back' from you are sent back to the form or if closed, closed the whole browser. When changed back to the orginal the thankyou page appeared but no email... Is there a simple answer to get BOTH actions working?! I would be forever thankful for anyone's assistance, this is my first live site and my client has been very patient so far...but time is ticking! Thanking anyone for any assistance! PS- I am a beginner, this is my first live site- go easy on me! Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/ Share on other sites More sharing options...
denno020 Posted February 21, 2013 Share Posted February 21, 2013 Well the first thing I noticed if that the action of your form is a HTML page.. I don't know how your php is supposed to run? And also I can't see where you've highlighted the line of HTML that you think is the problem. What you should do is make "send_form_email.php" the action of the form, then at the end of the script, use header('Location thankyou.html'); to forward the user on to the thankyou page. Hope that makes sense. Denno Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413869 Share on other sites More sharing options...
crispybean Posted February 21, 2013 Author Share Posted February 21, 2013 Thanks for the quick response Denno- just to clarify do I place the header in the PHP file? As below; <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "sales@xxxxxx.com.au"; $email_subject = "Order Received"; 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['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // 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 First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments 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 .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\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); header ('Location thankyou.html'); ?> <!-- include your own success html here --> <title>contactform</title> <h1>Thank you for your order - one of our friendly sales team will confirm your order soon</h1> Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413871 Share on other sites More sharing options...
denno020 Posted February 21, 2013 Share Posted February 21, 2013 Yep, right at the end of the php file. It will redirect the users browser. Also add an exit(); right after the header. Just to make sure the php script isn't processed any further. I know there isn't any more code after it, but I tend to put them together anyways. Denno Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413872 Share on other sites More sharing options...
crispybean Posted February 21, 2013 Author Share Posted February 21, 2013 (edited) Still no love! I now have this error appearing when I click submit. Parse error: syntax error unexpected $end in /home/dxxxxxxx/public_html/xxxxxxx.com.au/send_form_email.php on line 84 Here is the code as entered in DW, looks all kosher apart from a red highlighted line that has appeared on the line as mentioned above! There is no code on this line? <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "sales@xxxxxxxxx"; $email_subject = "Order Received"; 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['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // 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 First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments 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 .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\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); header('Location thankyou.html'); exit() ?> <!-- include your own success html here --> What have I done now?! :'( <title>contactform</title> <h1>Thank you for your order - one of our friendly sales team will confirm your order soon</h1> Edited February 21, 2013 by crispybean Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413878 Share on other sites More sharing options...
denno020 Posted February 21, 2013 Share Posted February 21, 2013 You need to do header('Location: thankyou.html'); Could you highlight which line the error is appearing on? Easier that than me having to count down to line 84 Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413879 Share on other sites More sharing options...
crispybean Posted February 21, 2013 Author Share Posted February 21, 2013 Ok, so I put in the : in the header, still coming up with the blank screen syntax message on clicking submit. Have attached a screenshot, the red highlight is on line 75 and the syntax error says its coming from line 84 (the very last line? Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413883 Share on other sites More sharing options...
denno020 Posted February 21, 2013 Share Posted February 21, 2013 You need a semi-colon after exit(); Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413885 Share on other sites More sharing options...
crispybean Posted February 21, 2013 Author Share Posted February 21, 2013 Aha...ok, put that in, still the same syntax error Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413888 Share on other sites More sharing options...
denno020 Posted February 21, 2013 Share Posted February 21, 2013 you haven't closed off your if curly brace from the start.. Put that below the exit -> } Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413889 Share on other sites More sharing options...
clarky0 Posted February 21, 2013 Share Posted February 21, 2013 What is the email address you are using to receive the mail too? Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413892 Share on other sites More sharing options...
clarky0 Posted February 21, 2013 Share Posted February 21, 2013 What is the email address you are using to receive the mail too? The line above your error is ?> make sure that opening line to that is "<? } " Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413893 Share on other sites More sharing options...
crispybean Posted February 21, 2013 Author Share Posted February 21, 2013 (edited) You little RIPPER! Thankyou Denno, I will be able to sleep tonight! Legend, your seeing eye found my illusive missing curly bracket! Edited February 21, 2013 by crispybean Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413894 Share on other sites More sharing options...
clarky0 Posted February 21, 2013 Share Posted February 21, 2013 The line above your error is ?> make sure that opening line to that is "<? } " Also is your file now called contactus.php ? Quote Link to comment https://forums.phpfreaks.com/topic/274765-contact-form-email-not-sending/#findComment-1413895 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.