简体   繁体   English

使用PHP发送邮件时,DKIM签名无法验证

[英]DKIM Signature not validating when sending mail with PHP

I was having a problem with gmail/hotmail filtering emails from my server as spam. 我的gmail / hotmail过滤来自我服务器的垃圾邮件问题。 The Spam Assassin score is quite low so I know that my IP isn't on any blacklists or such which means it is the filtering that gmail/hotmail use stopping the emails from coming through. 垃圾邮件刺客分数很低,所以我知道我的IP不在任何黑名单上,或者这意味着它是gmail / hotmail用来阻止电子邮件通过的过滤。

I did some research and read that using DKIM will possibly resolve the issues I am having. 我做了一些研究并读到使用DKIM可能会解决我遇到的问题。 I went ahead and enabled DKIM on my server. 我继续在我的服务器上启用DKIM。 Now when I send emails using my email client the tool located here ( http://www.brandonchecketts.com/emailtest.php ) reports the DKIM signature as valid. 现在,当我使用我的电子邮件客户端发送电子邮件时,此处的工具( http://www.brandonchecketts.com/emailtest.php )会将DKIM签名报告为有效。

The next step was to implement a DKIM signature into my PHP mails. 下一步是在我的PHP邮件中实现DKIM签名。 So I went ahead and used this DKIM class located here ( http://sourceforge.net/projects/dkim-class-php/ ) which is a spin-off of PHPMailer. 所以我继续使用这里的DKIM类( http://sourceforge.net/projects/dkim-class-php/ ),这是PHPMailer的衍生产品。

However, when I send emails now, despite containing a DKIM signature I am getting a strange error from the validation tool. 但是,当我现在发送电子邮件时,尽管包含DKIM签名,但我从验证工具中收到一个奇怪的错误。

result = fail
Details: message has been altered

You can see the full report here: http://www.brandonchecketts.com/emailtest.php?email=K86KTXpMbl%40www.brandonchecketts.com 您可以在此处查看完整报告: http//www.brandonchecketts.com/emailtest.php?email = K86KTXpMbl%40www.brandonchecketts.com

Thanks for any help, I am desperately trying to get this working and have been banging my head against a wall for several hours now. 感谢您的帮助,我拼命想让这个工作起来,并且已经在墙上撞了好几个小时了。

I gave an answer to this here : Setting up DomainKeys/DKIM in a PHP-based SMTP client 我在这里给出了答案: 在基于PHP的SMTP客户端中设置DomainKeys / DKIM

Basically what you need to ensure is that you supply all the headers that your MTA adds to your out-going email. 基本上您需要确保的是,您提供MTA添加到您的外发电子邮件中的所有标头。 Because different systems are configured differently, there is no one size fits all solution. 由于不同的系统配置不同,因此没有一种尺寸适合所有解决方案。

Look at the message source which has failed the the signing (and is giving the Message Altered error) to ascertain which headers were added. 查看签名失败的消息源(并给出消息已更改错误)以确定添加了哪些标头。 Typically your MTA will add the Message-ID and Date header (the Date header may also cause a low spam assasin score if it is missing, so you could as well include it!). 通常,您的MTA将添加Message-IDDate标头(如果缺少日期标题,也可能导致垃圾邮件刺客评分较低,因此您也可以包括它!)。

Another common mistake is that you alter the message yourself AFTER signing the message, so ensure no modifications are made in your code after you have signed your message. 另一个常见的错误是您在签署邮件后自己更改邮件,因此请确保在签署邮件后未对代码进行任何修改。

After determining which headers were added, then you should add those headers yourself (and therefore over-ride the default behaviour of your MTA adding them) to the email before signing. 在确定添加了哪些标头之后,您应该自己添加这些标头(因此将其添加的MTA的默认行为覆盖),然后再签名。

I found strange behavior of php mail() + postfix with dkim: 我用dkim发现了php mail()+ postfix的奇怪行为:

If you make 如果你做

$headers .= "From: USER <$from_email>\n";

DKIM will be incorrect, but if you do: DKIM不正确,但如果你这样做:

$headers .= "From: USER <" . $from_email . ">\n";

All OK! 一切都好! Strange. 奇怪。 Very strange. 很奇怪。 Also users recommended to make 也建议用户使用

trim($emailContent) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM