加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:45:09 所属栏目:PHP教程 来源:网络整理
导读:我尝试设置email.html和action.php,以便有人可以从网站发送电子邮件.这是email.html中的代码 form action="./action.php" method="post" pYour Name/p pinput type="text" name="name" //p pEmail/p pinput type="text" name="email" //p pServices/p pinput
我尝试设置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和接收端的其他此类反垃圾邮件措施.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读