使用 PHP Mailer 通过 GSuite 发送邮件时出现 DKIM 错误
DKIM error when sending mail with GSuite using PHP Mailer
我在 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();
我从邮件中收到一条错误消息-tester.com 显示我的 DKIM 无效。
我认为这是因为我从一个外部服务器发送(不是 Google)并且我的 MX 记录指向 Google,但我真的需要这些电子邮件来获取,我应该如何解决这个问题?
有没有办法在 PHP Mailer 中配置它?谢谢
它抱怨的原因是因为您根本没有与 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'];
我在 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();
我从邮件中收到一条错误消息-tester.com 显示我的 DKIM 无效。
我认为这是因为我从一个外部服务器发送(不是 Google)并且我的 MX 记录指向 Google,但我真的需要这些电子邮件来获取,我应该如何解决这个问题?
有没有办法在 PHP Mailer 中配置它?谢谢
它抱怨的原因是因为您根本没有与 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'];