繁体   English   中英

使用 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();

我从 mail-tester.com 收到一个错误,它读取我的 DKIM 无效。

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

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

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

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

首先,您需要创建您的 DKIM 密钥并将它们放入您的 DNS。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM