This question already has an answer here:
Question
On the website when I press submit for the email, It now does everything Correctly but I do not receive the email, someone please help?
PHP
<?php
$first_name = $_POST ['first_name'];
$last_name = $_POST ['last_name'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = "From:" . $first_name . $last_name;
$to = "Relentile@gmail.com";
$subject = "New Message";
print_r($_POST);
mail ($to, $subject, $message, $headers);
echo "Your Message has been sent";
?>
HTML
<form action="contact.php" name="contact_form" method="post">
<p>
First name:
<input name="first_name" type="text"/>
</p>
<p>
Last name:
<input name="last_name" type="text"/>
</p>
<p>
<br>
E-Mail:
<input name="email" type="text"/>
</p>
<br>
<p>Type your enquiry</p>
<p><textarea name"message"></textarea></p>
<p>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset">
</p>
</form>
Old Error Message + data it was sending (2nd Image)
</div>
Set from method post
as below.
<form action="contact.php" name="contact_form" method="post">
In address bar your data is sending through by default get
method.But you are using $_POST[]
in php file.So you are not getting values.
Also in contact.php
use $headers
as below:
$headers = "From:" . $first_name . $last_name;
And
mail ($to, $subject, $message,$headers);
also semicolon at end of $subject
variable.
$subject = "New Message";
and do following....
$first_name = test_input($_POST ['first_name']);
$last_name = test_input($_POST ['last_name']);
$email = test_input($_POST['email']);
$message = test_input($_POST['message']);
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
Where
1.Strip unnecessary characters (extra space, tab, newline) from the user input data (with the PHP trim() function)
2.Remove backslashes () from the user input data (with the PHP stripslashes() function)
Change your PHP
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = "From: " . $email;
$to = "relentile@gmail.com";
$subject = "New Message";
print_r($_POST);
mail($to, $subject, $message, $headers);
echo "Your Message has been sent";
It should now work. The headers must be in proper format (spacing). "From" header contains sender's e-mail address. When accessing an array in PHP, do not use spaces: wrong = $array ["blah"], good = $array["blah"]. The same applies for functions.