簡體   English   中英

如何使用PHP為dkim正確散列正文和標頭?

[英]How to properly hash body and headers with PHP for dkim?

我檢查了Eric Vyncke的PHP dkim腳本,並復制了他如何對電子郵件中設置的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()函數發送電子郵件:

https://github.com/breakermind/PHP-DKIM

適用於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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM