Contact Form Not Sending Data

Hi
I’m new to this and attempting to get a HTML contact form to send the data to an email address.
I have got to the point where I am receiving an email with the title of each section of the form but it does not contain what was submitted.

Attached is my HTML Form
Any suggestions would be appreciated.

This is my PHP code:

<?php $to = "[email protected]"; $subject = "Website Contact Form"; $name = $_POST['name'] ; $email_from = $_POST['email'] ; $telephone = $_POST['telephone'] ; $website = $_POST['website'] ; $message = $_POST['message'] ; $MESSAGE_BODY = "Name: ".$_POST["name"]."\n"; $MESSAGE_BODY .= "Telephone: ".$_POST["telephone"]."\n"; $MESSAGE_BODY .= "Email: ".$_POST["email"]."\n"; $MESSAGE_BODY .= "Website: ".$_POST["webiste"]."\n"; $MESSAGE_BODY .= "Message: ".nl2br($_POST["message"])."\n"; $message = $_POST['name' + 'message' + 'email' + 'telephone'] ; $from = $_POST['email'] ; $headers = "From:" . $from; mail($to,$subject,$MESSAGE_BODY,$headers); echo "Mail Sent."; ?>

contact_form_html.pdf (16.1 KB)

There are a few things in this code that need looking at so i have commented in the code.
[php]

<?php $to = "[email protected]"; $subject = "Website Contact Form"; $name = $_POST['name'] ; $email_from = $_POST['email'] ; // THIS VARIABLE IS UNUSED? $telephone = $_POST['telephone'] ; $website = $_POST['website'] ; $message = $_POST['message'] ; $MESSAGE_BODY = "Name: ".$_POST["name"]."\n"; $MESSAGE_BODY .= "Telephone: ".$_POST["telephone"]."\n"; $MESSAGE_BODY .= "Email: ".$_POST["email"]."\n"; $MESSAGE_BODY .= "Website: ".$_POST["webiste"]."\n"; // TYPO HERE!! $MESSAGE_BODY .= "Message: ".nl2br($_POST["message"])."\n"; // ANOTHER DUPLICATE $message = $_POST['name' + 'message' + 'email' + 'telephone'] ; // WHAT THE HECK IS THIS? $from = $_POST['email'] ; // THIS IS THE SAME AS THE UNUSED VARIABLE ABOVE $headers = "From:" . $from; mail($to,$subject,$MESSAGE_BODY,$headers); echo "Mail Sent."; ?>

[/php]

Try this:
[php]

<?php $to = "[email protected]"; $subject = "Website Contact Form"; $name = $_POST['name']; $email_from = $_POST['email']; $telephone = $_POST['telephone']; $website = $_POST['website']; $message = nl2br($_POST['message']); $MESSAGE_BODY = "Name: $name\n"; $MESSAGE_BODY .= "Telephone: $telephone\n"; $MESSAGE_BODY .= "Email: $email_from\n"; $MESSAGE_BODY .= "Website: $website\n"; $MESSAGE_BODY .= "Message: $message\n"; $headers = "From:" . $email_from; if(mail($to, $subject, $MESSAGE_BODY, $headers)) { echo "Mail Sent."; } else { echo 'Message NOT sent!'; } ?>

[/php]

As a sidenote may i suggest you stop copy/pasting your code as you run the risk of duplicating errors. To aid your learning of PHP you should type in each and every line.

Hope that helps,
Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service