【问题标题】:Send mail in phpmailer using DKIM Keys使用 DKIM 密钥在 phpmailer 中发送邮件
【发布时间】:2014-08-19 05:57:55
【问题描述】:

Currents 我正在使用 phpmailer 发送邮件。现在如何使用 DKIM 密钥在 phpmailer 中发送电子邮件

我在 phpmailer 类文件中搜索,我找到了下面的代码

    /**
     * DKIM selector.
     * @type string
     */
    public $DKIM_selector = '';

    /**
     * DKIM Identity.
     * Usually the email address used as the source of the email
     * @type string
     */
    public $DKIM_identity = '';

    /**
     * DKIM passphrase.
     * Used if your key is encrypted.
     * @type string
     */
    public $DKIM_passphrase = '';

    /**
     * DKIM signing domain name.
     * @example 'example.com'
     * @type string
     */
    public $DKIM_domain = '';

    /**
     * DKIM private key file path.
     * @type string
     */
    public $DKIM_private = '';

我能知道它是怎么可能的吗?

【问题讨论】:

  • 您遇到的具体问题是什么? cmets 似乎完全可以解释。
  • 我对此进行了试验,但无法使其发挥作用。我为 Sendmail 选择了 OpenDKIM 过滤器,它的优点是所有出站邮件都经过签名

标签: php email phpmailer dkim


【解决方案1】:

如果您查看PHPMailer unit tests,有一个如何设置 DKIM 的示例。

这里是您发送消息所需的基础知识(显然更改域、密钥路径和选择器以匹配您的配置,并添加密码(如果您使用));这也假设您打算使用与您的From 地址相同的标识符进行签名:

$mail->DKIM_domain = 'example.com';
$mail->DKIM_private = '/path/to/my/private.key';
$mail->DKIM_selector = 'phpmailer';
$mail->DKIM_passphrase = '';
$mail->DKIM_identity = $mail->From;

当您send() 邮件(而不是之前)时,它将使用这些设置生成 DKIM 签名。

【讨论】:

  • DKIM_selector 总是'phpmailer' 吗?
  • 感谢您的帮助。有关如何设置 DKIM 的完整指南,我整理了一份指南 yomotherboard.com/how-to-setup-email-server-dkim-keys
  • DKIM_identifier 现在是 DKIM_identity (PHPMailer 5.2.13)
  • DKIM_selector 是您的 DNS TXT 记录上的选择器键设置。并不总是像示例中那样使用 phpmailer。
  • 要使用私钥字符串而不是设置文件路径,您可以简单地在 phpMailer 对象上指定 $mail -> DKIM_private_string 属性。
【解决方案2】:

我有以下经验:

  1. http://dkim.worxware.com/createkeys.php 生成的密钥对可能用于 SHA1,而 class.phpmailer.php 的最新版本 5.2.14 用于 SHA256。
    上面的示例不起作用。
  2. 我将 class.phpmailer.php 中的所有设置和函数从 SHA1 上的 SHA256 更改(我只是将所有字符串 SHA256 替换为字符串 SHA1)。
    我的 DKIM 签名 PHP 脚本已经可以使用了。

【讨论】:

  • 花了我几个小时才发现这是我的问题!非常令人沮丧!我使用这个站点来生成我的密钥socketlabs.com/domainkey-dkim-generation-wizard。使用最新版本的 phpmailer (5.2.14) 工作正常
  • 避免使用 SHA1 系列函数。今年早些时候发布了对 SHA1 的实际攻击 (shattered.io)。有很多关于如何使用 openssl 生成 DKIM 密钥对的说明。此外,让第三方网站为您生成任何安全密钥通常不是一个好主意。如果他们存储密钥,他们可以冒充您。相反,使用 openssl 离线生成它。
猜你喜欢
  • 2014-09-05
  • 2012-02-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-29
  • 2014-09-27
  • 2020-01-10
  • 2011-12-07
  • 2014-04-28
相关资源
最近更新 更多