没有从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和接收端的其他此类反垃圾邮件措施.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...