问题描述
我已经浏览了Eric Vyncke的PHP 并复制了他为电子邮件中设置的DKIM标头设置了哈希值。
$ pre $ $ DKIM_bh = base64_encode(pack('H *',sha1($ body)));
可以这样使用:
'bh ='。$ DKIM_bh。';'// ...
然而,当我时,它告诉我该散列没有'
$ headers。='DKIM-Signature:v = 1; A = RSA-SHA1; C =轻松/简单; Q = DNS / TXT; bh ='; // ...
$ body ='测试PHP + SMTP认证邮件,3。';
bh ='。base64_encode(pack('H *',sha1($ body)))。';'; // ...
我不确定我错过了什么? 以下是使用dkim和php mail()函数发送电子邮件的示例函数: 适用于Gmail.com和多部分/带有附件的混合信息! I've gone through Eric Vyncke's PHP dkim script and copied how he was doing hashes for DKIM headers set in emails Would be used as so: However when I validate the email message it tells me that the hash doesn't match. I'm not sure what I'm missing? How do I properly hash the body and headers so I can set the DKIM values for the header properly? Here is example functions how to send emails with dkim and php mail() function: https://github.com/breakermind/PHP-DKIM Works on Gmail.com and multipart/mixed messages with attachments! 这篇关于如何正确使用PHP为dkim散列正文和标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
<?php
//发送简单电子邮件,无DKIM显示
//你的电子邮件
$ name ='Name Jony';
$ sender ='[email protected]';
$ to ='[email protected]';
$ subject ='简单的html消息与dkim';
$ headers =
'MIME-Version:1.0
From:'。$ name。'<'。$ sender。'>
Content-type:text / html;字符集= UTF8’ ;
$ message =
'< html>
< header>< / header>
< body>
您好,这是一个DKIM测试电子邮件
< / body>
< / html>';
//现在你会做(设置配置文件和DNS记录之后):
//确保换行符是CRLF格式 - 签署
$ message = preg_replace('/(?,$ message);
$ headers = preg_replace('/(?<!\r)\\\
/',\r\\\
,$ 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 = $签名 - > get_signed_headers($ to,$ subject,$ message,$ headers);
//发送电子邮件
ini_set('sendmail_from',$ sender);
回复邮件($ to,$ subject,$ message,$ signed_headers。$ headers);
die();
$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))).';';//...
<?php
// Send simple email without DKIM SIgning
// YOUR E-MAIL
$name = 'Name Jony';
$sender = '[email protected]';
$to = '[email protected]';
$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();