Andy Rivers Posted December 20, 2011 Share Posted December 20, 2011 I have a simple form which when a person fills out will send the results to a specified email address and display a thank you page to the visitor and finally redirect to another page. Everything seems to work except the results do not get sent to the email - can anyone help? I think it might be to do with the checkboxes - how are these processed to email? Here is the Code: The Form - survey.html ---------------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- table { background-color: #9C9; } --> </style> </head> <body> <form id="form1" name="form1" method="post" action="check.php"> <table width="500" border="0" cellspacing="2" cellpadding="2"> <tr> <td><label for="name2">Name:</label></td> <td><input type="text" name="name" id="name2" /></td> </tr> <tr> <td>Continent</td> <td><p> <label> <input type="radio" name="continent" value="Asia" id="continent_0" /> Asia</label> <br /> <label> <input type="radio" name="continent" value="Europe" id="continent_1" /> Europe</label> <br /> <label> <input type="radio" name="continent" value="Africa" id="continent_2" /> Africa</label> <br /> <label> <input type="radio" name="continent" value="North America" id="continent_3" /> North America</label> <br /> <label> <input type="radio" name="continent" value="South America" id="continent_4" /> South America</label> <br /> <label> <input type="radio" name="continent" value="Antarctica" id="continent_5" /> Antarctica</label> <br /> <label> <input type="radio" name="continent" value="Australia" id="continent_6" /> Australia</label> <br /> </p></td> </tr> <tr> <td>Favourite Color</td> <td><p> <label> <input type="checkbox" name="color[]" value="Orange" id="color_0" /> Orange</label> <br /> <label> <input type="checkbox" name="color[]" value="Yellow" id="color_1" /> Yellow</label> <br /> <label> <input type="checkbox" name="color[]" value="Blue" id="color_2" /> Blue</label> <br /> <label> <input type="checkbox" name="color[]" value="Red" id="color_3" /> Red</label> <br /> <label> <input type="checkbox" name="color[]" value="Other (Please Specify)" id="color_4" /> Other (Please Specify)</label> <label for="othercolor"></label> <input type="text" name="othercolor" id="othercolor" /> <br /> </p></td> </tr> <tr> <td><label for="comments">Your Comments:</label></td> <td><textarea name="comments" id="comments" cols="45" rows="5"></textarea></td> </tr> <tr> <td><label for="submit"></label> <input type="submit" name="submit" id="submit" value="Submit" /></td> <td> </td> </tr> </table> <p> </p> </form> </body> </html> The PHP - check.php ---------------------- <?php /*Subject and Email Variables*/ $emailSubject = 'check.php'; $webMaster = 'substituteyouremailhere'; /*Gathering Data Variables*/ $name = $_POST['name']; $continent = $_POST['continent']; $color = $_POST['color']; $othercolor = $_POST['othercolor']; $comments = $_POST['comments']; $body = <<<EOD <br><hr><br> Visitors Name: $name<br> Visitors Continent: $continent<br> Visitors Favourite Color: $color<br> Other Favourite Color: $othercolor 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 xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Thanks - Survey Complete</title> <meta http-equiv="refresh" content="5;URL=http://www.google.com"> </head> <body> <p>Success - Thanks for completing the Form - We will get back to you soon!</p> </body> </html> EOD; echo "$theResults"; ?> Any help would be great - thanks ;-) Quote Link to comment https://forums.phpfreaks.com/topic/253553-form-to-email/ Share on other sites More sharing options...
iPixel Posted December 20, 2011 Share Posted December 20, 2011 Are you sure your web server is setup to send out emails? try if($success = mail(.....)) Quote Link to comment https://forums.phpfreaks.com/topic/253553-form-to-email/#findComment-1299771 Share on other sites More sharing options...
Pikachu2000 Posted December 20, 2011 Share Posted December 20, 2011 Where is $email defined? You're apparently sending a blank From: header. Most often the From: header should be set to a valid email address associated with the server. Quote Link to comment https://forums.phpfreaks.com/topic/253553-form-to-email/#findComment-1299799 Share on other sites More sharing options...
Andy Rivers Posted December 21, 2011 Author Share Posted December 21, 2011 Hey iPixel, Pikachu2000: Yes - the server is set up to receive e-mails. I am using an online service which has worked in the past with no problems. Just for the online I have set the specified email as some text, in reality I include a valid email - although this would be a hotmail, gmail type address - would that matter? /*Subject and Email Variables*/ $emailSubject = 'check.php'; $webMaster = 'substituteyouremailhere'; It is again referenced towards the end with the following php code: $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); Thanks for the suggestions, Andy ;-) Quote Link to comment https://forums.phpfreaks.com/topic/253553-form-to-email/#findComment-1300039 Share on other sites More sharing options...
AyKay47 Posted December 21, 2011 Share Posted December 21, 2011 to reiterate previously mentioned material. Where are you declaring the value of $email before using it here $headers = "From: $email\r\n"; also, if the mail() function is returning false, it will be returning an error. Are you receiving any errors? make sure error_reporting is E_ALL or 1 Quote Link to comment https://forums.phpfreaks.com/topic/253553-form-to-email/#findComment-1300062 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.