Rolladome Posted October 10, 2009 Share Posted October 10, 2009 Hi I'm new to PHP but i scripted a contact form on my website that has all the normal fields name, email address etc. But the emails that i recieve from the form appear blank except for the field names so something like Name: Email: Message: Mailinglist: I've looked at the scripting and I can't see anything wrong can someone help me? This is the code: <?php /*Subject and Email Variables*/ $emailSubject = 'New Form Entry'; $webMaster = 'rolladome@btinternet.com'; /*Gathering Data Variables*/ $nameField = $_POST['name']; $emailField = $_POST['email']; $phoneField = $_POST['phone']; $messageField = $_POST['message']; $mailinglistField = $_POST['mailinglist']; $body = <<<EOD Name: $name <br> Email Address: $email <br> phone: $phone <br> Message: $message <br> Mailing List: $mailinglist EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /*Results Rendered as HTML*/ $theResults = <<<EOD <html> <head> <meta http-equiv="refresh" content="3;URL=http://www.rolladome.org.uk/contact.html"> <title>Message Sent!</title> <style type="text/css"> <!-- .style2 { font-size: medium; font-family: Geneva, Arial, Helvetica, sans-serif; font-weight: bold; color: #000000; } --> </style> </head> <body> <p align="center" class="style2">Thank you for your interest, Your email will be answered very soon!</p> <p align="center" class="style2">you will be returned to the RollaDome Website in a few seconds....</p> </body> </html> EOD; echo "$theResults"; ?> Quote Link to comment Share on other sites More sharing options...
waynewex Posted October 10, 2009 Share Posted October 10, 2009 It could be because you're not doing any error checking? You should be checking to see if the the message field was filled in etc. if(strlen(trim($message)) == 0){ $error = "Please type a message"; } Quote Link to comment Share on other sites More sharing options...
ameyemad Posted October 10, 2009 Share Posted October 10, 2009 i also noticed you have... $nameField = $_POST['name']; $emailField = $_POST['email']; $phoneField = $_POST['phone']; $messageField = $_POST['message']; $mailinglistField = $_POST['mailinglist']; and then you have... Name: $name <br> Email Address: $email <br> phone: $phone <br> Message: $message <br> Mailing List: $mailinglist Quote Link to comment Share on other sites More sharing options...
cags Posted October 10, 2009 Share Posted October 10, 2009 On top of what ameyemad says... this topic is practically identical to one that appeared a few days ago. Once you have fixed the problem that ameyemad has pointed out if it doesn't work place... echo '<pre>'; print_r($_POST); echo '</pre>'; To the top of the code, and check to see what appears on screen when you submit your form. If you get just Array { } Then the form is not submitting properly. In the other thread the problem was on the HTML form. The OP had an attribute for encode type of something like plain/text. Removing that solved the problem. 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.