通过 php 邮件功能发送电子邮件进入垃圾邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18229279/
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
sending email via php mail function goes to spam
提问by Dinesh Nagar
I am facing problem in sending mail to my inbox (gmail account) but everytime it goes to spam folder. Here is the code snippet
我在将邮件发送到我的收件箱(gmail 帐户)时遇到问题,但每次都发送到垃圾邮件文件夹。这是代码片段
//$ticketDetail is array which contain required information to send.
sendOwnershipEmail('[email protected]', $ticketDetail);
function sendOwnershipEmail($email, $ticketDetail) {
$param = new stdClass();
$param->content = "<div>
<div><b>".$ticketDetail[0]['ticket_number']."</b></div><br/>
<div><img src='".$ticketDetail[0]['image_path']."'/></div><br/>
<div>Ticket with ticket number ".$ticketDetail[0]['ticket_number']." has been requested for tranfer from <div/>
<div>".$ticketDetail[0]['oldDepartment']." to ".$ticketDetail[0]['newDepartment']." Department <div/>
</div>";
$param->sendTo = $email;
$param->subject = "Request for Department transfer";
sendMailFunction($param);
}
function sendMailFunction($param) {
$to = $param->sendTo;
$subject = $param->subject;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: [email protected]' . "\r\n";
$message = "<html><head>" .
"<meta http-equiv='Content-Language' content='en-us'>" .
"<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>" .
"</head><body>" .$param->content.
"<br><br></body></html>";
mail($to, $subject, $message, $headers);
}
And I have tried a lot like setting headers as Reply-To, Return-Path etc but every time it goes to spam. Can u please figure out whats the problem?
我已经尝试了很多,比如将标题设置为回复、返回路径等,但每次都是垃圾邮件。你能弄清楚是什么问题吗?
采纳答案by dognose
The problem is simple that the PHP-Mail function is not using a well configured SMTP Server.
问题很简单,PHP-Mail 功能没有使用配置良好的 SMTP 服务器。
Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.
如今,电子邮件客户端和服务器对电子邮件发送服务器执行大量检查,例如反向 DNS 查找、灰名单和 whatevs。所有这些测试都将因 php mail() 函数而失败。如果您使用的是动态 ip,那就更糟了。
Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.
使用 PHPMailer-Class 并将其配置为使用 smtp-auth 以及配置良好的专用 SMTP 服务器(本地服务器或远程服务器),您的问题就消失了。
回答by Funk Forty Niner
Try changing your headers to this:
尝试将您的标题更改为:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: [email protected]" . "\r\n" .
"Reply-To: [email protected]" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
For a few reasons.
出于几个原因。
One of which is the need of a
Reply-To
and,The use of apostrophes instead of double-quotes. Those two things in my experience with forms, is usually what triggers a message ending up in the Spam box.
其中之一是需要一个
Reply-To
和,使用撇号代替双引号。根据我对表单的经验,这两件事通常会触发垃圾邮件框中的消息。
You could also try changing the $from
to:
您也可以尝试将其更改$from
为:
$from = "[email protected]";
EDIT:
编辑:
See these links I found on the subject https://stackoverflow.com/a/9988544/1415724and https://stackoverflow.com/a/16717647/1415724and https://stackoverflow.com/a/9899837/1415724
请参阅我在该主题上找到的这些链接https://stackoverflow.com/a/9988544/1415724和https://stackoverflow.com/a/16717647/1415724和https://stackoverflow.com/a/9899837/1415724
https://stackoverflow.com/a/5944155/1415724and https://stackoverflow.com/a/6532320/1415724
https://stackoverflow.com/a/5944155/1415724和https://stackoverflow.com/a/6532320/1415724
Try using the SMTP server of your ISP.
Using this apparently worked for many:
X-MSMail-Priority: High
尝试使用 ISP 的 SMTP 服务器。
使用这个显然对许多人有用:
X-MSMail-Priority: High
http://www.webhostingtalk.com/showthread.php?t=931932
http://www.webhostingtalk.com/showthread.php?t=931932
"My host helped me to enable DomainKeys and SPF Records on my domain and now when I send a test message to my Hotmail address it doesn't end up in Junk. It was actually really easy to enable these settings in cPanel under Email Authentication. I can't believe I never saw that before. It only works with sending through SMTP using phpmailer by the way. Any other way it still is marked as spam."
“我的主机帮助我在我的域上启用了 DomainKeys 和 SPF 记录,现在当我向我的 Hotmail 地址发送测试邮件时,它不会以垃圾邮件结束。在电子邮件身份验证下在 cPanel 中启用这些设置实际上非常容易。我不敢相信我以前从未见过。顺便说一下,它只能用于使用 phpmailer 通过 SMTP 发送。任何其他方式它仍然被标记为垃圾邮件。”
PHPmailer sending mail to spam in hotmail. how to fix http://pastebin.com/QdQUrfax
PHPmailer 将邮件发送到 hotmail 中的垃圾邮件。如何修复 http://pastebin.com/QdQUrfax
回答by Patrick
If you are sending this through your own mail server you might need to add a "Sender" header which will contain an email address of from your own domain. Gmail will probably be spamming the email because the FROM address is a gmail address but has not been sent from their own server.
如果您通过自己的邮件服务器发送此邮件,您可能需要添加一个“发件人”标头,其中包含来自您自己域的电子邮件地址。Gmail 可能会发送垃圾邮件,因为发件人地址是一个 Gmail 地址,但不是从他们自己的服务器发送的。
回答by Emile
回答by Nazehs
One thing that I have observed is likely the email address you're providing is not a valid email address at the domain. like [email protected]. The email should be existing at Google Domain. I had alot of issues before figuring that out myself... Hope it helps.
我观察到的一件事是您提供的电子邮件地址可能不是域中的有效电子邮件地址。像[email protected]。该电子邮件应存在于 Google Domain。在自己弄清楚之前我遇到了很多问题......希望它有所帮助。
回答by Valentin
Be careful with your tests. If you in your form you put the same email as the email address which must receiveit will be directly in spam :)
小心你的测试。如果您在表单中输入与必须接收的电子邮件地址相同的电子邮件,则会直接在垃圾邮件中:)