如何使用PHP for dkim正确地散列正文和标题?

如何使用PHP for dkim正确地散列正文和标题?,php,hash,dkim,Php,Hash,Dkim,我浏览了Eric Vyncke的PHP,并复制了他是如何对电子邮件中设置的DKIM头进行哈希运算的 $DKIM_bh = base64_encode(pack('H*', sha1($body))); 将用作: 'bh='.$DKIM_bh.';'//... 但是,当我看到它告诉我哈希不匹配时 $headers .= 'DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/simple; q=dns/txt; bh=';//... $body = 'Test

我浏览了Eric Vyncke的PHP,并复制了他是如何对电子邮件中设置的DKIM头进行哈希运算的

$DKIM_bh = base64_encode(pack('H*', sha1($body)));
将用作:

'bh='.$DKIM_bh.';'//...
但是,当我看到它告诉我哈希不匹配时

$headers .= 'DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/simple; q=dns/txt; bh=';//...

$body = 'Test PHP+SMTP authenticated email,3.';

bh='.base64_encode(pack('H*', sha1($body))).';';//...

我不确定我错过了什么如何正确散列正文和标题,以便正确设置标题的DKIM值?

以下是如何使用DKIM和php mail()函数发送电子邮件的示例函数:

适用于Gmail.com和带有附件的多部分/混合邮件

<?php
// Send simple email without DKIM SIgning
// YOUR E-MAIL
$name = 'Name Jony';
$sender = 'sdsdso@domain.pl';
$to = 'ffffu@gmail.com';
$subject = 'Simple html message with dkim';

$headers =
'MIME-Version: 1.0
From: "'.$name.'" <'.$sender.'>
Content-type: text/html; charset=utf8';

$message =
'<html>
    <header></header>
    <body>
        Hello, this a DKIM test e-mail
    </body>
</html>';

// NOW YOU WILL DO (after setting up the config file and your DNS records) :
// Make sure linefeeds are in CRLF format - it is essential for signing
$message = preg_replace('/(?<!\r)\n/', "\r\n", $message);
$headers = preg_replace('/(?<!\r)\n/', "\r\n", $headers);

require_once 'mail-signature.class.php';
require_once 'mail-signature.config.php';

$signature = new mail_signature(
    MAIL_RSA_PRIV,
    MAIL_RSA_PASSPHRASE,
    MAIL_DOMAIN,
    MAIL_SELECTOR
);
$signed_headers = $signature -> get_signed_headers($to, $subject, $message, $headers);

// Send email
ini_set('sendmail_from', $sender);
echo mail($to, $subject, $message, $signed_headers.$headers);
die();

以下是如何使用dkim和php mail()函数发送电子邮件的示例函数:

适用于Gmail.com和带有附件的多部分/混合邮件

<?php
// Send simple email without DKIM SIgning
// YOUR E-MAIL
$name = 'Name Jony';
$sender = 'sdsdso@domain.pl';
$to = 'ffffu@gmail.com';
$subject = 'Simple html message with dkim';

$headers =
'MIME-Version: 1.0
From: "'.$name.'" <'.$sender.'>
Content-type: text/html; charset=utf8';

$message =
'<html>
    <header></header>
    <body>
        Hello, this a DKIM test e-mail
    </body>
</html>';

// NOW YOU WILL DO (after setting up the config file and your DNS records) :
// Make sure linefeeds are in CRLF format - it is essential for signing
$message = preg_replace('/(?<!\r)\n/', "\r\n", $message);
$headers = preg_replace('/(?<!\r)\n/', "\r\n", $headers);

require_once 'mail-signature.class.php';
require_once 'mail-signature.config.php';

$signature = new mail_signature(
    MAIL_RSA_PRIV,
    MAIL_RSA_PASSPHRASE,
    MAIL_DOMAIN,
    MAIL_SELECTOR
);
$signed_headers = $signature -> get_signed_headers($to, $subject, $message, $headers);

// Send email
ini_set('sendmail_from', $sender);
echo mail($to, $subject, $message, $signed_headers.$headers);
die();

请不要把你的例子贴到你能找到的任何地方;我可以请你阅读网址不起作用请不要把你的例子张贴在你能找到的任何地方;我可以请你阅读网址不起作用吗