【问题标题】:DKIM error when sending mail with GSuite using PHP Mailer使用 PHP Mailer 使用 GSuite 发送邮件时出现 DKIM 错误
【发布时间】:2019-10-08 01:27:17
【问题描述】:

我在 A2 托管,但我使用 GSuite 来处理我的所有邮件。

当我从 Gmail 向 mail-tester.com 发送测试邮件时,我得到了非常好的评价。

但是,当我使用 PHP 脚本发送消息时:

$mail = new PHPMailer(true);
ob_start();

//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER;                // Enable verbose debug output
$mail->Host       = 'smtp.gmail.com';                 // Set the SMTP server to send through
$mail->SMTPAuth   = true;                             // Enable SMTP authentication
$mail->Username   = $pickuploc . '@xxxx.com';                 // SMTP username
$mail->Password   = 'xxx';  
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;   // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port       = 587;                              // TCP port to connect to

//Recipients
$mail->setFrom($pickuploc . '@xxx.com', 'xxx xxxx');
$mail->addAddress($email, $fname . " " . $lname);     // Add a recipient
$mail->addBCC($pickuploc . '@xxx.com');

// Content
$mail->isHTML(true);                                  // Set email format to HTML
include 'email-confirmed.html';
$mail->Subject = 'Your Reservation Has Been Confirmed!';
$mail->Body    = ob_get_clean();
$mail->AltBody = 'Your reservation has been confirmed.';

$mail->send();

我从 mail-tester.com 收到一条错误消息,显示我的 DKIM 无效。

我认为这是因为我从国外服务器(不是 Google)发送,而我的 MX 记录指向 Google,但我确实需要这些电子邮件才能收到,我应该如何解决这个问题?

有没有办法在 PHP Mailer 中进行配置?谢谢。

【问题讨论】:

    标签: php email phpmailer google-workspace dkim


    【解决方案1】:

    它抱怨的原因是因为你根本没有和 DKIM 签约!

    您可以使用 PHPMailer 进行 DKIM 签名,但需要进行一定的设置。 PHPMailer 提供了一些代码来帮助您做到这一点。确保您使用的是PHPMailer 6.1.1 or later;旧版本存在影响 DKIM 签名的错误。

    首先您需要create your DKIM keys 并将它们放入您的 DNS 中。

    现在您需要修改脚本以使用您的私钥对消息进行签名,如this example 所示;您需要添加的部分是:

    //This should be the same as the domain of your From address
    $mail->DKIM_domain = 'example.com';
    //See the DKIM_gen_keys.phps script for making a key pair -
    //here we assume you've already done that.
    //Path to your private key:
    $mail->DKIM_private = 'dkim_private.pem';
    //Set this to your own selector
    $mail->DKIM_selector = 'phpmailer';
    //Put your private key's passphrase in here if it has one
    $mail->DKIM_passphrase = '';
    //The identity you're signing as - usually your From address
    $mail->DKIM_identity = $mail->From;
    //Suppress listing signed header fields in signature, defaults to true for debugging purpose
    $mail->DKIM_copyHeaderFields = false;
    //Optionally you can add extra headers for signing to meet special requirements
    $mail->DKIM_extraHeaders = ['List-Unsubscribe', 'List-Help'];
    

    【讨论】:

    • 我不知道如何从 G Suite 获取 DKIM 私钥或任何其他私钥 - 你能帮忙吗?
    • 该链接表明 Google 不会提供私钥,那么我将如何设置它以与 GSuite 一起使用?
    • 点击第一个链接 - 您需要创建自己的密钥并将它们放在您自己的域的 DNS 中。你不需要谷歌的密钥。
    • 我完全按照说明进行操作,我使用服务器上提供的脚本生成了公钥和私钥,但是当我尝试使用tools.sparkpost.com/dkim 对其进行测试时,我收到“签名失败无法被验证”帮助?
    • 目前我正在处理 6.1 中的一些 DKIM 问题,请密切关注新版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-22
    • 1970-01-01
    • 2015-01-07
    • 1970-01-01
    • 2012-07-28
    • 2012-09-05
    • 2015-09-03
    相关资源
    最近更新 更多