spicey Posted August 14, 2008 Share Posted August 14, 2008 I've got my php form to work and sends an email but the information the someone would enter into the form does not appear in the email that I receive. Not sure what I am missing. I have tried many different things but nothing has worked. Please help! This is my php file: <?php $name = $_REQUEST['name'] ; $organization = $_REQUEST['organization'] ; $email = $_REQUEST['email'] ; $telephone = $_REQUEST['telephone'] ; $date_required = $_REQUEST['date_required'] ; $checkbox_adult = $_REQUEST['checkbox_adult'] ; $adults = $_REQUEST['adults'] ; $checkbox_children = $_REQUEST['checkbox_children'] ; $children = $_REQUEST['children'] ; $leaving_from = $_REQUEST['leaving_from'] ; $destination = $_REQUEST['destination'] ; $return_to = $_REQUEST['return_to'] ; $time_departure = $_REQUEST['time_departure'] ; $time_return = $_REQUEST['time_return'] ; $additional_info = $_REQUEST['additional_info'] ; $checkbox_email = $_REQUEST['checkbox_email'] ; $checkbox_telephone = $_REQUEST['checkbox_telephone'] ; mail("name@website.ca", "Quote Request", $message, "From: $email"); header ( "Location: http://www.website.ca/thank_you.html"); ?> This works but the information requested does not appear in the email. I used Dreamweaver to create my form, and chose the following: Action: sendmail.php Method: POST Target: left this blank Enctype: left this blank (options are application/x-www-form-urlencoded or multipart/form-data) have tried both and nothing and still does not work. If you need more information, please let me know...thanks to whoever helps - your assistance is greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/119679-information-from-form-does-not-appear-in-email-help/ Share on other sites More sharing options...
JonnoTheDev Posted August 14, 2008 Share Posted August 14, 2008 Because the variable you are using $message has not been assigned any data. Simple as that mail("name@website.ca", "Quote Request", $message, "From: $email"); You'll probably want it displayed different but heres a quick fix foreach($_REQEUST as $key => $val) { $message .= $key.": ".$val."\n\n"; } mail("name@website.ca", "Quote Request", $message, "From: $email"); Quote Link to comment https://forums.phpfreaks.com/topic/119679-information-from-form-does-not-appear-in-email-help/#findComment-616587 Share on other sites More sharing options...
spicey Posted August 14, 2008 Author Share Posted August 14, 2008 I knew it was something to that...I just tried you short code and now have errors... would the following work: mail ("name@website.ca", "Quote Request", $_REQUEST, "From $email"); instead of using $message but within $_REQUEST do I add all of the different items (name organization, etc.) would this work? The error I got was as follows: (I checked my brackets to make sure everything matched up with open and close) Warning: Invalid argument supplied for foreach() in /mnt/w0106/d00/s28/b02d7599/www/website.ca/sendmail.php on line 20 Warning: Cannot modify header information - headers already sent by (output started at /mnt/w0106/d00/s28/b02d7599/www/website.ca/sendmail.php:20) in /mnt/w0106/d00/s28/b02d7599/www/website.ca/sendmail.php on line 23 Quote Link to comment https://forums.phpfreaks.com/topic/119679-information-from-form-does-not-appear-in-email-help/#findComment-616629 Share on other sites More sharing options...
JonnoTheDev Posted August 14, 2008 Share Posted August 14, 2008 OK if you get the error Warning: Invalid argument supplied for foreach() This indicates that the loop does not contain an array as the first value. If the error is coming from the follwoing foreach foreach($_REQEUST as $key => $val) { $message .= $key.": ".$val."\n\n"; } Then this implies that there is no request data to the form processing page so $_REQUEST does not exist. Your form is submitting to sendmail.php and using the POST method. Not sure why you have used $_REQUEST instead of $_POST but anyway you should be able to check the values entered in the form on your sendmail.php file by using print_r($_POST); Here is an example for your sendmail.php file: <?php // process the form when submit is clicked if(isset($_POST['action']) && $_POST['action'] == 'post') { $msg = "Name: ".$_POST['name']."\n\n"; $msg .= "Email: ".$_POST['email']; mail ("joe@bloggs.com", "Quote Request", $msg, "me@mydomain.com"); header("Location:successpage.php"); } ?> <form method="POST" action="sendmail.php"> <input type="hidden" name="action" value="post" /> Name: <input type="text" name="name" /><br /> Email: <input type="text" name="email" /><br /> <input type="submit" name="submit" value="submit" /> </form> You should not use this code in a live environment as the form data has not been validated before being put into an email. This leaves the form wide open to spammers, especially if you are using the email address inputted in the form as a sending address. You should look at cleaning your data before it goes in an email function. This is also the case when saving user input into database tables. Quote Link to comment https://forums.phpfreaks.com/topic/119679-information-from-form-does-not-appear-in-email-help/#findComment-616944 Share on other sites More sharing options...
spicey Posted August 15, 2008 Author Share Posted August 15, 2008 Thank you all for your help - greatly appreciated. Everything now works fine. I have validated everything as well - hopefully I did it right. Thanks to all of you who answered my questions, I have now successfully completed my first php form. Thanks again!!! Quote Link to comment https://forums.phpfreaks.com/topic/119679-information-from-form-does-not-appear-in-email-help/#findComment-617110 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.