Question:
How To Set Up A PHP Contact Form?
Joshua
2010-12-20 22:50:23 UTC
Im trying to setup a php contact form.
I created a html and the php file the whole process works except for when i receive a message it only states the subject with no name,no email,no body.
I was told i have to put everything into one variable.
Does anyone know how to do this?
Thanks

This is my PHP code


$name = $_post['name'];
$email = $_post['email'];
$comments = $_post['comments'];


//TO, Subject, Message, Header
mail('info@steadfastpainting.com', 'Comments', $text, 'From: '.$name.' '.$email.'>');
header('Location: thankyou.html');
?>


This is my HTML





Contact Form



name


email


comments





Four answers:
just "JR"
2010-12-21 01:32:05 UTC
Your parameters for the mail() function are incorrect.

Here is the corrected code: (removed blank lines before "header" as well)




$name = $_POST['name']; // POST upper case: I have (rarely) experimented some case sensitive.

$email = $_POST['email'];

$comments = $_POST['comments'];

//TO, Subject, Message, Header

$headers = "From: " . $email . "\r\n"; // EXACTLY as it is!

$subject = "Mail from " . $name;

$to = "info@steadfastpainting.com";

mail ($to, $subject, $comments, $headers);

header('Location: thankyou.html');

?>
anonymous
2016-04-25 05:24:54 UTC
Take out the $headers from mail($emailTo, $subject, $body, $headers); and see if the email sends without problem. if it does, put it back in and remove the spaces between the ' . "\r in the $headers function I think that you have some extra spaces in there and it is throwing off the escape characters \r\n
John
2010-12-20 23:08:21 UTC
looks like you're missing a coma in the header area but post it on phpfreaks.com and you'll have the right answer ten times over. Good luck!
Alex Szasz
2010-12-20 23:20:54 UTC
You are not assigning the $text variable. Try to use $comments instead.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...