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

标签 php sendmail postfix-mta phpmailer dkim

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

我安装了 postfix 服务和 DKIM-Milter 来生成 key 。

如果我使用命令行发送邮件,它工作正常,并且邮件带有显示“signed-by:mydomain.com”的 DKIM 签名

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

希望对你有帮助

关于php - 如何使用带有 DKIM 签名的 Phpmailer 发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8705035/

相关文章:

jQuery onClick 打印屏幕并发送图像电子邮件

node.js - 在 Node js 中测试 catchAll 电子邮件的域

amazon-web-services - 如何使用带有 Postfix 的 AWS SES 接收退回的邮件

java - 如何从树中打印中缀?

php - SOAP - 加载本地 WSDL 文件

php - 如何用后端数据填充 Zend_Layout 变量?

php - 让 array_sum 在 Laravel PHP 的每个 foreach 循环中添加总计。

php - 在插入数据库之前检查项目的唯一性

ssl - 使用 xampp 为 sendmail 功能启用 SSL 证书

c# - .NET Core MailKit SMTP AUTH LOGIN 作为本地 linux 帐户