没有从PHP mail()方法接收电子邮件

前端之家收集整理的这篇文章主要介绍了没有从PHP mail()方法接收电子邮件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试设置email.html和action.PHP,以便有人可以从网站发送电子邮件.这是email.html中的代码
<form action="./action.PHP" method="post">
    <p>Your Name</p>
    <p><input type="text" name="name" /></p>
    <p>Email</p>
    <p><input type="text" name="email" /></p>
    <p>Services</p>
    <p><input type="text" name="service" /></p>
    <p>Requests</p>
    <p><textarea rows="8" cols="32" name="comment"></textarea></p>
    <p><input type="submit" value="Send" /></p>
</form>

在action.PHP我有

<?PHP
    $to = "foo@outlook.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "foo2@gmail.com";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent.";
?>

在email.html中输入的信息成功加载到action.PHP中,但我的Outlook收件箱中没有从电子邮件方法收到任何内容.我错过了什么吗?

首先检查邮件的返回值,以查看SMTP服务器是否正在接收邮件.

另外,根据Namecheap的文档,your From address is invalid.

Only domains that are hosted on our servers can be used in ‘From’
field. Any domain that is not hosted with us cannot be added to ‘From’
field. We had to take this measure to prevent sending spam using
forums,guest books and contact forms scripts. For your site scripts
to work properly you should set ‘From’ field to email account that has
been created in your cPanel.

即使您的托管公司允许这样做,您也不应该使用非Gmail服务器从@ gmail.com发送邮件.它通常是blocked by SPF和接收端的其他此类反垃圾邮件措施.

原文链接:https://www.f2er.com/php/138559.html

猜你在找的PHP相关文章