NicoleStrain Posted February 6, 2017 Share Posted February 6, 2017 Hello I have a PHP contact from for a website im making. The form is sending the email ok however the content in the email is wrong as its sending the HTML script. Im only using Notepad ++ to make the website and that dosent have a error checker so i used a website called http://phpcodechecker.com/ but that said there is no errors in my code which there must be. Could someone have a check for me please ? This is my first time using PHP so it probably a silly mistake. Thanks in advanced ! <?php if(isset($_POST['email'])) { // CHANGE THE TWO LINES BELOW $email_to = "nicoles@mailmarkscot.com"; $email_subject = "Website Bookin"; function died($error) { // your error code can go here echo "We're sorry, but there's errors found with the form you submitted.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } $name = $_POST['name']; $email_address = $_POST['email']; $tell = $_POST['tell']; $date = $_POST['date']; $service = $_POST['service']; $eMessage = $_POST['message']; $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; $message = ' <html> <head> <p> You have received a new booking request. <br/> Name: $name <br/> Email: $email_address <br/> Tell: $tell <br/> Date: $date <br/> Service: $tell <br/> Message: $eMessage </p> </body> </html> '; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject,$message,$headers); ?> <!-- place your own success html below --> Thank you for contacting us. We will be in touch with you very soon. <?php } die(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/303112-php-contact-from/ Share on other sites More sharing options...
ginerjm Posted February 6, 2017 Share Posted February 6, 2017 Why not try to send a plain text email until you learn to do the right research to send an html-based one? Also - add error checking at the top of your script to point out php problems as they occur. And - don't bury a function into the middle of your code. It interrupts the flow of reading the code for no reason. Question - what is died() even used for? Question 2 - what is $email_exp for? Question 3 - if you are going to use html, where is the <body> tag? Quote Link to comment https://forums.phpfreaks.com/topic/303112-php-contact-from/#findComment-1542361 Share on other sites More sharing options...
NicoleStrain Posted February 6, 2017 Author Share Posted February 6, 2017 Hello thanks for replying, I hadnt realized that i was missing the body tag, ive been playing about with that much ive deleted it at one point by accident. I got the code from a demo file offline which i altered to my contact from so being completely honest im not sure what died() or $email_exp is used for. Ill take your advice but and stick to a plan text email until ive learned more, would rather have an email that works instead of one that looks good. Quote Link to comment https://forums.phpfreaks.com/topic/303112-php-contact-from/#findComment-1542362 Share on other sites More sharing options...
ginerjm Posted February 6, 2017 Share Posted February 6, 2017 Well said! I appreciate your honest response to the things I wrote about. Be happy to review and advise on your next post - especially if you do the things I suggested. See my signature for the error checking code you need to add. And - you should actually try to learn from doing your own research instead of just copying other's (feeble) attempts. You will have a much faster education. Quote Link to comment https://forums.phpfreaks.com/topic/303112-php-contact-from/#findComment-1542363 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.