这是一个已经在我的雷达一段时间,并无法找到一个明确的答案在这个线程在这个线程的任何地方的原始问题。我现在已经能够实现用PHP/Pear发送DKIM签名的SMTP电子邮件。以下是所需的步骤。
我找到了DKIM的修改版本从http://www.ra726.net/blog/2010/07/20/sending-email-to-gmail-from-php-without-being-marked-as-spam/(您可以通过http://www.ra726.net/php-dkim.zip下载)。如果你已经实现了DKIM并且只需要使它与SMP邮件一起工作,那么你所需要的就是dkim.php文件,正如博客所说的那样,该文件稍作修改以处理作为数组传递的头文件。在我的代码中,我将其命名为dkimNEW.php。
确保包含大多数标头,以便MTA在签名后不会修改消息。在我有限的研究中,最多添加的头文件是Date和Message-ID头文件,因此我的头文件数组看起来像这样:注意:我使用它来发送html电子邮件,并进行更改以适合!此外,添加您的域名作为邮件ID的最后一部分
$headers = array(
'Subject' => $subject,
'From' => $from,
'To' => $to,
'MIME-Version' => '1.0',
'Date' => date('r'),
'Message-ID' => '<'.sha1(microtime(true)).'@yourdomain.com>',
'Content-Type' => 'text/html',
'Content-Transfer-Encoding' => 'quoted-printable',
); // end $headers
然后你会得到利用上述修改dkim.php签署您的电子邮件和签名添加到阵列头,又名
require 'dkimNEW.php';
$dkim = AddDKIM($headers, $subject, $body);
$headers['DKIM-Signature'] = $dkim;
代码的其余部分是正常码通过与PHP/SMTP梨发送电子邮件。完整的工作代码是:
<?php
require_once 'Mail.php';
require_once 'Mail/mime.php';
// set all of the parameters
$subject = 'Test of DKIM';
$from = 'My Name <[email protected]>';
$to = 'First Recipient <[email protected]>';
$pbody ='<html><head></head><body><h1>Done! DKIM test</h1>Result, next?</body></html>';
$text = strip_tags($pbody);
// create the headers
$headers = array(
'Subject' => $subject,
'From' => $from,
'To' => $to,
'MIME-Version' => '1.0',
'Date' => date('r'),
'Message-ID' => '<'.sha1(microtime(true)).'@mydomain.com>',
'Content-Type' => 'text/html',
'Content-Transfer-Encoding' => 'quoted-printable',
); // end $headers
// create the message
$mime = new Mail_mime("\n");
$mime->setTXTBody($text);
$mime->setHTMLBody($pbody);
// always call these methods in this order
$body = $mime->get();
$headers = $mime->headers($headers);
require 'dkimNEW.php' ;
$dkim = AddDKIM($headers, $subject, $body);
$headers['DKIM-Signature'] = $dkim;
// create the smtp mail object
$smtp_params = array(
'host' => 'mail.mydomain.com',
'auth' => true,
'username' => 'myUserName',
'password' => 'myPassWord',
); // end $smtp_params
$smtp = Mail::factory('smtp', $smtp_params);
// send the message
$recipients = array('[email protected]', '[email protected]');
$mail = $smtp->send($recipients, $headers, $body);
?>
PS。以防万一您没有注意到,请用您自己的值替换!
因此,使DKIM与SMTP电子邮件(甚至PHP邮件)一起工作所需的一切就是确保您指定由MTA添加到您的电子邮件中的所有标题,然后签署标题,邮件的主题和正文,并最终将您的标题包含在签名部分中。
下投票 \t 下面是例子功能是如何发送电子邮件与DKIM和PHP mail()函数: https://github.com/breakermind/PHP-DKIM – 2017-09-26 12:07:48