php 邮件作为垃圾邮件发送 - phpmailer,如何避免
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16302962/
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
mail delivered as spam - phpmailer, how to avoid
提问by Subodh Ghulaxe
I know that in first look many users mark this question as duplicate, but after reading more than 10 question I did not get any satisfactory answer, almost all question has answers having words like "There's not much you can do about it.", "I am not sure", "There is no sure shot trick" etc. that's why I am writing this question, and I think this is very generalized questions and every php developer faces it at least once, ok enough speech :) , now my question is..
我知道,乍一看,很多用户将这个问题标记为重复,但是在阅读了 10 多个问题后,我没有得到任何满意的答案,几乎所有问题的答案都带有诸如“您无能为力。”,“我不确定”,“没有确定的技巧”等等。这就是我写这个问题的原因,我认为这是非常笼统的问题,每个 php 开发人员至少都遇到过一次,好的演讲:),现在我的问题是..
I working on a project management application and am using phpmailer to send mail when any task is created or anybody comments on any bug mails are sent to related users, actually instead of sending mails as soon the action happens I have created a 'notifications' table where I actually save all mail data and a cron script then send all mails, here is some part of my cron script.
我正在开发一个项目管理应用程序,并且在创建任何任务或将任何错误邮件的任何评论发送给相关用户时,我使用 phpmailer 发送邮件,实际上不是在操作发生时立即发送邮件,而是我创建了一个“通知”表我实际保存所有邮件数据和 cron 脚本然后发送所有邮件的地方,这是我的 cron 脚本的一部分。
$query = "select * from notifications where 1 ";
$projects = $obj_basic->get_query_data($query);
if(!empty($projects))
{
foreach($projects as $data)
{
$message = html_entity_decode($data['content'], ENT_QUOTES);
list($ton, $email) = get_name_email($data['to']);
if(!empty($email))
{
$query = "select send_notification from users where email='$email' AND send_notification !='1' ";
$users = $obj_basic->get_query_data($query);
if(!empty($users))
{
$deleteQuery = "delete from notifications where id ='".$data['id']."'";
$obj_basic->run_query($deleteQuery, 'DELETE');
continue;
}
$comment_id = $data['reference_id'];
$attribute = $data['attribute'];
$mail = new PHPMailer();
list($fromName, $fromEmail) = get_name_email($data['from']);
if(!empty($comment_id) && $attribute == 'comment')
{
$fromEmail = '[email protected]';
}
$mail->SetFrom($fromEmail, $fromName);
$mail->AddReplyTo($fromEmail, $fromName);
$mail->AddAddress($email, $ton);
$mail->BouncedTo = $fromEmail;
$mail->IsHTML(true);
$mail->Subject = $data['subject'];
$mail->Body = $message;
$MessageID = "<".md5($comment_id.'_'.$email).'@changewebaddress.com>';
$mail->MessageID= $MessageID;
if($mail->Send()) {
if(!empty($comment_id) && $attribute == 'comment')
{
$query = "SELECT message_id FROM `project_comments` WHERE `id`='$comment_id'; ";
$project_comments = $obj_basic->get_query_data($query, 'SELECT');
if(!empty($project_comments))
{
$project_comments[0]['message_id'] = html_entity_decode(trim($project_comments[0]['message_id'], ","));
$query = "UPDATE `project_comments` SET `message_id`=CONCAT_WS(',', '".mysql_escape_string($project_comments[0]['message_id'])."', '".mysql_escape_string(html_entity_decode($MessageID))."') WHERE `id`='$comment_id'; ";
$obj_basic->run_query($query, 'UPDATE');
}
}
$deleteQuery = "delete from notifications where id ='".$data['id']."'";
$obj_basic->run_query($deleteQuery, 'DELETE');
}
}
}
}
as per what I have tested everything look good, since I am using phpmailer it sets required header it also sets 'Return-Path:' and 'Reply-To:' in header.
根据我测试过的一切看起来都不错,因为我使用的是 phpmailer,它设置了所需的标头,它还在标头中设置了“返回路径:”和“回复:”。
Is there any exact solution on this issue
这个问题有没有确切的解决方案
回答by Sammitch
- Make sure all of the required headers are being set.
- Check to see if there are any additional, optional headers that you should be setting.
- Sending an HTML/multipart message with mismatched text/HTML sections is frowned upon by some filters.
- Absolutely any mail that you send programmatically should have either a link or instructions on how to opt out. This is usually only enforced by human-curated blacklists and the abuse department at your ISP.
- Make sure your SMTP server is not blacklisted or has a poor reputation.
- Make sure your web serverdoes not have a poor reputation. Some scanners include the reputation of every MTA in the chain.
- Review the content of your messages before sending them. If anything in it could even roughly be construed as trying to sell something to someone, change it.
- Sacrifice a small animal to the dark gods of email and hope against hope.
- Check the headers of the messages marked as spam to see if the spam filtering system left any useful information about why it was blocked.
- Ask the receiving server's admins why the message was blocked.
- Accept that there is no, and never will be an "exact solution on this issue". Ever.
- 确保设置了所有必需的标题。
- 检查是否有您应该设置的任何其他可选标题。
- 某些过滤器不赞成发送文本/HTML 部分不匹配的 HTML/多部分消息。
- 当然,您以编程方式发送的任何邮件都应该包含有关如何选择退出的链接或说明。这通常仅由人工策划的黑名单和 ISP 的滥用部门强制执行。
- 确保您的 SMTP 服务器未被列入黑名单或声誉不佳。
- 确保您的Web 服务器没有不良声誉。一些扫描程序包括链中每个 MTA 的声誉。
- 在发送消息之前查看消息的内容。如果其中的任何内容甚至可以粗略地解释为试图向某人出售某些东西,请更改它。
- 向电子邮件的黑暗之神献祭一只小动物,希望对希望。
- 检查标记为垃圾邮件的邮件的标题,看看垃圾邮件过滤系统是否留下了有关其被阻止原因的任何有用信息。
- 询问接收服务器的管理员为什么消息被阻止。
- 接受没有,也永远不会有“这个问题的确切解决方案”。曾经。
回答by M8R-1jmw5r
Is there any exact solution on this issue
这个问题有没有确切的解决方案
Unfortunately not. It is a non-trivial issue with much complexity which prevents exact solutions.
不幸的是没有。这是一个非常复杂的问题,它阻止了精确的解决方案。
Instead you need to find out for each email that is marked as spam what led to the spam scoring of it and reverse-engineer that then to the part(s) of the software and systems you use - either configuration (improve the configuration and setup) or processing (patch the software you use and re-compile/deploy).
相反,您需要为每封标记为垃圾邮件的电子邮件找出导致垃圾邮件评分的原因,然后对您使用的软件和系统的部分进行逆向工程 - 无论是配置(改进配置和设置) 或处理(修补您使用的软件并重新编译/部署)。
If you want to improve the situation here on this website - you wrote that many existing questions are disappointing - please keep a worklog of that doing and document each case. Put this as an answer here so that future users can benefit from that. That would be not doing the same mistakes as the previous users have been done on site not doing this documentation and hence the information is missing.
如果你想改善这个网站上的情况——你写了许多现有的问题令人失望——请保留一份工作日志并记录每个案例。将其作为答案放在这里,以便未来的用户可以从中受益。这不会像以前的用户在现场没有做这个文档那样犯同样的错误,因此信息丢失。
回答by Mandu
The accepted answer has a lot of good advice in it. Additionally, adding an SPF record to my DNS helped avoid spam filters. Learn more about SPF records:
接受的答案中有很多很好的建议。此外,将 SPF 记录添加到我的 DNS 有助于避免垃圾邮件过滤器。了解有关 SPF 记录的更多信息:
http://en.wikipedia.org/wiki/Sender_Policy_Framework
http://en.wikipedia.org/wiki/Sender_Policy_Framework
Microsoft has a tool to help create such records:
Microsoft 有一个工具可以帮助创建此类记录:
http://www.microsoft.com/mscorp/safety/content/technologies/senderid/wizard/
http://www.microsoft.com/mscorp/safety/content/technologies/senderid/wizard/
回答by kpp
I know this already has an accepted answer but this is for others who might have had the same problem like me and ended up here. I had a website and mails send from my website ended up in spam boxes. Even if I tried using phpmailer and adding our companies mail-server as an SMTP.
我知道这已经有一个公认的答案,但这适用于可能和我一样遇到同样问题并最终来到这里的其他人。我有一个网站,从我的网站发送的邮件最终进入了垃圾邮件箱。即使我尝试使用 phpmailer 并将我们公司的邮件服务器添加为 SMTP。
However this could easily be resolved by sort of white listing the IP address of the website to the send filter of your mail server. How this is done exactly I don't know because the admin of the mail server did this for me(google it I guess).
然而,这可以通过将网站的 IP 地址列入白名单到您的邮件服务器的发送过滤器来轻松解决。我不知道这是如何完成的,因为邮件服务器的管理员为我做了这件事(我猜是谷歌)。
Doing this means that if the receiving side does a DNS lookup or an IP lookup to your mail server. The mail-server tells the receiving side that it indeed was sent from him or his associating IP addresses and therefor it will not end up in the spambox.
这样做意味着如果接收方对您的邮件服务器进行 DNS 查找或 IP 查找。邮件服务器告诉接收方它确实是从他或他的关联 IP 地址发送的,因此它不会在垃圾邮件箱中结束。
However if you do this there is no need for the phpmailer and the standard mail() function works too.
但是,如果您这样做,则不需要 phpmailer 并且标准的 mail() 函数也可以工作。