May 23, 200818 yr I am having trouble with my contact form and need some assistance. The form works and the PHP code sends me an email, but the information is not shown on the email, just the field names. Which part of the PHP code will fix this? I have very little knowlegde when it comes to PHP, so I don't have a clue! Thanks! HTML Contact Form <style type="text/css"> <!-- .style2 {font-family: Verdana, Arial, Helvetica, sans-serif} --> </style> <form action="sendmail.php" method="post" name="form" id="form"> <h2 class="style2"><img src="Images/formtitle.jpg" width="357" height="52" hspace="9" vspace="1" /></h2> <ul> <label><span class="style2">Name</span></label><br /> <input type="text" class="style2" id="Name" /> <br /> <br /> <label><span class="style2">Email</span></label><br /> <input type="text" class="style2" id="Email" /> <br /> <br /> <label><span class="style2">Message</span></label> <br /> <textarea cols="40" rows="6" class="style2"></textarea> <br /> <br /> <p><input name="submit" type="submit" class="style2" value="Submit"> </ul> </form> PHP Code <?php $emailSubject = 'Funky Favours Enquiry'; $webMaster = 'example@hotmail.com'; $nameField = $_POST['name']; $emailField = $_POST['email']; $messageField = $_POST['message']; $body = <<<EOD <br><hr><br> Name: $name <br> Email: $email <br> Message: $message <br> EOD; $headers = "From: $email\r\n"; $headers = "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); $theResults = <<<EOD <html> <style type="text/css"> <!-- .style2 {font-family: Verdana, Arial, Helvetica, sans-serif} --> </style> <form method="post" action="sendmail.php"> <form id="form"> <h2 class="style2"><img src="Images/formtitle.jpg" width="357" height="52" hspace="9" vspace="1" /></h2> <ul> <label><span class="style2">Name</span></label><br /> <input type="text" class="style2" id="Name" /> <br /> <br /> <label><span class="style2">Email</span></label><br /> <input type="text" class="style2" id="Email" /> <br /> <br /> <label><span class="style2">Message</span></label> <br /> <textarea cols="40" rows="6" class="style2"></textarea> <br /> <br /> <p><input name="submit" type="submit" class="style2" value="Submit"> </ul> </form> </html> EOD; echo"$theResults"; ?> Thanks
May 23, 200818 yr Give each of your form input fields a name attribute the same as the id atribute .eg <input type="text" class="style2" name="Email" id="Email" /> In your php script change the following: $body = <<<EOD <br><hr><br> Name: $name <br> Email: $email <br> Message: $message <br> EOD; to $body = <<<EOD <br><hr><br> Name: $nameField <br> Email: $emailField <br> Message: $messageField <br> EOD;
May 23, 200818 yr Author Code is still not working, there is no information inside the email from the form. I have changed the code to; HTML Code <style type="text/css"> <!-- .style2 {font-family: Verdana, Arial, Helvetica, sans-serif} --> </style> <form action="sendmail.php" method="post" name="form" id="form"> <h2 class="style2"><img src="Images/formtitle.jpg" width="357" height="52" hspace="9" vspace="1" /></h2> <ul> <label><span class="style2">Name</span></label><br /> <input type="text" class="style2" name="Name" id="Name" /> <br /> <br /> <label><span class="style2">Email</span></label><br /> <input type="text" class="style2" name="Email" id="Email" /> <br /> <br /> <label><span class="style2">Message</span></label> <br /> <textarea cols="40" rows="6" class="style2" name="Message" id="Message"></textarea> <br /> <br /> <p><input name="submit" type="submit" class="style2" value="Submit"> </ul> </form> PHP Code <?php $emailSubject = 'Funky Favours Enquiry'; $webMaster = 'kay346@hotmail.com'; $nameField = $_POST['name']; $emailField = $_POST['email']; $messageField = $_POST['message']; $body = <<<EOD <br><hr><br> Name: $nameField <br> Email: $emailField <br> Message: $messageField <br> EOD; $headers = "From: $email\r\n"; $headers = "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); $theResults = <<<EOD <html> <style type="text/css"> <!-- .style2 {font-family: Verdana, Arial, Helvetica, sans-serif} --> </style> <form method="post" action="sendmail.php"> <form id="form"> <h2 class="style2"><img src="Images/formtitle.jpg" width="357" height="52" hspace="9" vspace="1" /></h2> <ul> <label><span class="style2">Name</span></label><br /> <input type="text" class="style2" id="Name" /> <br /> <br /> <label><span class="style2">Email</span></label><br /> <input type="text" class="style2" id="Email" /> <br /> <br /> <label><span class="style2">Message</span></label> <br /> <textarea cols="40" rows="6" class="style2"></textarea> <br /> <br /> <p><input name="submit" type="submit" class="style2" value="Submit"> </ul> </form> </html> EOD; echo"$theResults"; ?> Were am I going wrong??? Thanks
May 23, 200818 yr Change the following $nameField = $_POST['name']; $emailField = $_POST['email']; $messageField = $_POST['message']; to $nameField = $_POST['Name']; $emailField = $_POST['Email']; $messageField = $_POST['Message'];
May 25, 200818 yr Author A problem has now appeared on line 9. How can I fix this? $body = <<<EOD Thanks
May 29, 200818 yr maybe this script will be the best for you http://www.webdesignerforum.co.uk/index.ph...ost&p=48558 enjoy
June 2, 200818 yr Author I managed to fix the PHP code and make it work eventually. Turned out PHP was throwing a wobbler over spaces and punctuation. Thanks for all the help!
June 4, 200818 yr Hey, i have choose to use this form and all seems fine apart from on submision i get the following error. Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 80 in /home/sites/mywebsite.co.uk/public_html/me.php on line 47 Here is line 47 } elseif (preg_match($profanity, $value) || (preg_match($spamwords, $value)) { Any suggestions?
Create an account or sign in to comment