I am having a strange problem. The following code segment prints Send and the email is successfully delivered to my inbox
$from_name ="John Doe";
$from_mail = "someemail@gmail.com";
$to = "someemail@gmail.com";
$subject = "Test Mail";
$mail_body = "This is email test";
$message = $mail_body ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8\r\n";
$headers .= "From: ".$from_name." <".$from_mail.">\r\n";
$sendmail=mail($to,$subject,$message,$headers);
if($sendmail)
{
echo json_encode("Send");
}
else
{
echo json_encode("Not Send");
}
Now the next segment I am about to show is nearly the same, but I get the inputs from POST.
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$to_email = "someemail@gmail.com";
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$subject = "Contact from website";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8\r\n";
$headers .= "From: ".$name." <".$email.">\r\n";
$sendmail = mail($to_email, $subject, $message, $headers);
if($sendmail)
{
echo json_encode("Send");
}
else
{
echo json_encode("Not Send");
}
}
Now the above also prints Send, but no email is actually delivered, not even to my Spam folder. I have dumped all the POST variables and they all contain the data I expect them to. If I check it out in the Net tab of firebug, I can also see that the data is posted
email someemail@gmail.com
message dsfsdfsdfsdf
name John Doe
I have checked the server logs and there are no errors. $to_email is set to my email address.
Is there anything that stands out as to why the first one sends and the second one does not, even though they both produce the output Send?
Thanks