php - mail() function wont work properly
977
I have to following code that works but not the way i want it
if(isset($_POST['edit']) && $_POST['edit']!="")
{
// Email Information
$firstName = $_POST['fname'];
$lastName = $_POST['lname'];
$mobile = $_POST['contactNumber'];
$comments = $_POST['message'];
$email_from = $_POST['email'];
$email_to = "[email protected]";
//$email_headers = "From: ". $firstName ." ". $lastName . " <" . $email_from . ">\r\n" . "Reply-To: [email protected]";
$email_headers = "From: $firstName $lastName <[email protected]>" . "\r\n" . "Reply-To: [email protected]";
$email_subject = "Munster Wedding DJs Inquiry!";
$email_body = "\nName: " . $firstName . " " . $lastName .
"\nEmail: " . $email_from .
"\nPhone Number: " . $mobile .
"\nMessage: " . $comments;
// Send Email
$mailerResult = @mail($email_to, "$email_subject", $email_body,
$email_headers, '-f ' . $email_from);
// Check For Errors
if($mailerResult) {
//echo "Mail Sent!";
echo '<script>document.location.href="thanks.html#anchor"</script>';
exit();
} else {
// echo "Error Sending Email!" . "<br><br>";
// print_r(error_get_last());
}
}
If I change
From: $firstName $lastName <[email protected]>"
to
From: $firstName $lastName <$email_from>"
The form doesnt send an email? Why is this?
All i want to do is recieve the email and when i click reply it put users email address into the "to" field.
Answer
Solution:
Try using like this, < ; for < > ; for >
remove the space between < and ;