如何使用带有DKIM签名的Phpmailer发送电子邮件?

我正在使用PHPmailer发送电子邮件.

我安装了postfix服务和DKIM-Milter来生成密钥.

如果我使用命令行发送邮件,它的工作正常,邮件是DKIM签名显示“签名: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=

但我想使用PHPmailer(5.1)发送支持DKIM签名的邮件,但返回此信息:

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=

我检查了class.phpmailer.php文件,它有一些DKIM选项:

  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    = '';

如何配置此选项?我知道公钥和私钥,但是$DKIM_private和$DKIM_identity是什么?

解决方法:

$DKIM_private用于你的私钥和$DKIM_identity,我不确定,但它是可选的,你可以在这里找到更多信息:http://dkim.org/specs/draft-allman-dkim-base-01.html#anchor9.这是一些示例代码.

$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';

希望有所帮助

上一篇:PHPmailer重复电子邮件问题 – 使用$mail-> Send()的条件语句


下一篇:php – 尝试访问google.com以获取本地Web应用程序时出错