How to send email with Phpmailer with DKIM signature?

时光总嘲笑我的痴心妄想 提交于 2019-12-09 03:18:46

问题


I`m using PHPmailer to sent email.

I installed postfix service and DKIM-Milter to generate the key.

It works fine if i use command line to sent mail, and the mail is with DKIM signature displaying "signed-by:mydomain.com"

Authentication-Results: mx.google.com; spf=pass (google.com: domain of root@mydomain.com designates 182.50.xxx.xxx as permitted sender) smtp.mail=root@mydomain.com; dkim=pass header.i=@mydomain.com

DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mydomain.com; s=default;
    t=1325531456; bh=+gZFhu4Id2AXb8UVbFLzDVVlChWGhvxvJUIdjdMLQsk=;
    h=To:Subject:Message-Id:Date:From;
    b=mH4GV8ayicc6UMn1uopCc9VJb5v2MiOKQpEtwJjckzoJ8ePhRKQIZI5KnzSdSoSP3
     BtmehOQhMn9kIR/TlL2dlSog2EkRNeAaWcmO1K3khtCZ7rkXHGJsDn9C6l49K0tJa2
     rplPOSI7wS8+3NCEiuc5sjZimPo4v9WuTECVqxkg=

But i want to use PHPmailer (5.1) to sent mail with DKIM signature supported, but returns this:

Authentication-Results: mx.google.com; spf=pass (google.com: domain of info@mydomain.com designates 182.50.xxx.xxx as permitted sender) smtp.mail=info@mydomain.com; dkim=neutral (bad format) header.i=info@mydomain.com

DKIM-Signature: v=1; a=rsa-sha1; q=dns/txt; l=70; s=default;
    t=1325533594; c=relaxed/simple;
    h=From:To:Subject;
    d=mydomain.com; i=@mydomain.com;
    z=
    |
    |Subject:=20Testing=20email=20from=20phpmailer;
    bh=lC+16EvauA2HuJG03ArE6CtgLuY=;
    b=

I checked the class.phpmailer.php file, and it has some DKIM options:

  public $DKIM_selector   = 'default';

  /**
   * Used with DKIM DNS Resource Record
   * optional, in format of email address 'you@yourdomain.com'
   * @var string
   */
  public $DKIM_identity   = '';

  /**
   * Used with DKIM DNS Resource Record
   * optional, in format of email address 'you@yourdomain.com'
   * @var string
   */
  public $DKIM_domain     = '';

  /**
   * Used with DKIM DNS Resource Record
   * optional, in format of email address 'you@yourdomain.com'
   * @var string
   */
  public $DKIM_private    = '';

How to configure this option? I know the public key and private key, but what`s is $DKIM_private and $DKIM_identity?


回答1:


$DKIM_private is for your private key and $DKIM_identity, well I'm not sure, but it's optional, and you can find more info here: http://dkim.org/specs/draft-allman-dkim-base-01.html#anchor9. Here is some example code.

$mail->DKIM_domain = 'mydomain.com';
$mail->DKIM_private = '/path/to/private_key';
$mail->DKIM_selector = 'default'; //this effects what you put in your DNS record
$mail->DKIM_passphrase = '1234567';

Hope that helps




回答2:


You need to break up the DKIM-Signature header such that each property appears on a new line. The PHPMailer implementation of DKIM has some issues that must be corrected.

The $DKIM_identity value is optional. To understand the role of $DKIM_private, see the DKIM_Sign method.




回答3:


Start here

http://dkim.worxware.com/

At the bottom - click Continue....

It will alow you to generate private/public key with instructions

In brief: - setup to send using the private/public key file to add dkim headers in email header - modify DNS txt record for the public key




回答4:


I found that the latest version uses sha256 instead of sha1 so the existing DKIM generator (http://dkim.worxware.com/) doesn't work unless you go into the class.phpmailer.php file and edit all the mentions of sha256 back to sha1, doing this fixes issues with verifiers not being able to use sha256 for the public key (giving an error)



来源:https://stackoverflow.com/questions/8705035/how-to-send-email-with-phpmailer-with-dkim-signature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!