没有收到来自PHP mail()方法的电子邮件 [英] Not receiving email from the PHP mail() method

查看:155
本文介绍了没有收到来自PHP mail()方法的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试设置一个email.html和一个action.php,以便有人可以从网站发送电子邮件。以下是email.html中的代码

I have tried to set-up an email.html and an action.php so that someone can send an email from a website. Here is the code in 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中我有

In action.php I have

<?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中没有收到任何内容收件箱中的电子邮件方式。我错过了什么吗?

The information entered in email.html successfully load into action.php, but nothing is received in my Outlook inbox from the email method. Am I missing something?

推荐答案

首先检查邮件的返回值查看邮件是否被SMTP服务器接受。

Start by checking the return value of mail to see if the message is being accepted by your SMTP server.

另外,根据Namecheap的文档,您的From地址无效

Also, per Namecheap's documentation, your From address is invalid.


只有在我们的服务器上托管的域可以在'From'
字段中使用。任何未托管我们的域名都不能添加到'From'
域中。我们不得不采取这一措施,以防止使用
论坛,访客图书和联系表单脚本发送垃圾邮件。对于您的站点脚本
正常工作,您应该将From字段设置为在您的cPanel中创建了
的电子邮件帐户。

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发送邮件。它通常会被SPF阻止等接收端的这种反垃圾邮件措施。

Even if this were allowed by your hosting company, you shouldn't be sending mail from @gmail.com using non-Gmail servers anyway. It will often be blocked by SPF and other such anti-spam measures on the receiving end.

这篇关于没有收到来自PHP mail()方法的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆