我遇到了一个奇怪的问题。以下代码段打印发送,电子邮件已成功发送到我的收件箱
$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");
}
现在我要展示的下一个片段几乎相同,但我从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");
}
}
现在上面也打印发送,但实际上没有发送电子邮件,甚至没有发送到我的垃圾邮件文件夹。我已经转储了所有POST变量,它们都包含我期望它们的数据。如果我在firebug的Net选项卡中查看它,我也可以看到数据已发布
email someemail@gmail.com
message dsfsdfsdfsdf
name John Doe
我检查了服务器日志,没有错误。 $ to_email设置为我的电子邮件地址。
是否有任何突出显示为什么第一个发送而第二个不发送,即使它们都产生输出发送?
由于