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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19070872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:47:27  来源:igfitidea点击:

Not receiving email from the PHP mail() method

phpemail

提问by jh_

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

我试图设置一个 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>

In action.php I have

在 action.php 我有

<?php
    $to = "[email protected]";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "[email protected]";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent.";
?>

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?

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

回答by quietmint

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

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

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

此外,根据 Namecheap 的文档,您的发件人地址无效

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.

只有托管在我们服务器上的域才能用于“发件人”字段。任何不是由我们托管的域都不能添加到“发件人”字段。我们必须采取这一措施来防止使用论坛、留言簿和联系表单脚本发送垃圾邮件。为了使您的站点脚本正常工作,您应该将“发件人”字段设置为在您的 cPanel 中创建的电子邮件帐户。

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 SPFand other such anti-spam measures on the receiving end.

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

回答by Bernd Ott

First check result of the mail. You also should check the php error log file.

首先检查邮件的结果。您还应该检查 php 错误日志文件。

when your mail is really going out, use an valid sender email, the you can get bounces from the receiving mail server.

当您的邮件真正发出时,请使用有效的发件人电子邮件,您可以从接收邮件服务器收到退回邮件。

don't forget, there are many anti spam technology's. most important is that you respect and know how SPFis working. that's one of the most fails, websites doesn't send emails which don't arrive at recipient.

不要忘记,有许多反垃圾邮件技术。最重要的是您尊重并了解SPF的工作原理。这是最失败的问题之一,网站不会发送未到达收件人的电子邮件。

回答by Mitech

Well, banged my head hard.. Just to realise they were going in Spam folder of my "$to" email id. Also check this on your side.

好吧,狠狠地敲了敲我的头......只是意识到他们进入了我的“$to”电子邮件ID的垃圾邮件文件夹。也请检查这一点。