Jump to content

information from form does not appear in email - help!


Recommended Posts

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! :)

 

 

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");

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

 

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.

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!!! :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.