【问题标题】:Change Message-ID PHPMailer更改消息 ID PHPMailer
【发布时间】:2021-11-07 20:49:53
【问题描述】:

您好,我正在制作一个基于 php 的邮件应用程序,它将与外部 smtp 服务器连接并发送电子邮件。现在我已经成功匹配了所有内容,但 Message-ID 的 @domain-name 和 Sender 域名不匹配...

这是我得到的结果: Wrong Message ID Header

这就是我应该得到的结果(这封电子邮件是从 Mailwizz 发送的,它与我尝试连接我的应用程序的同一 SMTP 服务器相连)

Expected Message ID Header

send.php 文件,我使用 PHPMailer 与 SMTP 连接


use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/Exception.php';
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';

$mail = new PHPMailer;

$mail->isSMTP();
$mail->Host = 'smtp*****************';
$mail->SMTPAuth = true;
$mail->Username = 'notify@send.al***********';
$mail->Password = '**********';
$mail->SMTPSecure = 'tls';
$mail->Port = 80;

$mail->SetFrom('jon@al***********','John Adams');
$mail->Sender = 'notify@send.al*********';
$mail->addAddress('*********@gmail.com');
$mail->Subject = 'Hello This is a TEST FROM SMTP';
$mail->isHTML(false);
$mail->Body = 'Hello let me know when its received';
$mail->addCustomHeader('X-Sender', 'notify@send.al**********');
$mail->XMailer=null;
$mail->MessageID = md5('HELLO'.(idate("U")-1000000000).uniqid()).'-'.$type.'-'.$id.'@send.al*********';
if(!$mail->send()){
    echo 'Error is '.$mail->ErrorInfo;
}
else{
    echo 'Message has been sent!';
}
?>

【问题讨论】:

  • 我不是说有相同的消息ID,我只是提到消息后的@domainname与发送域不同
  • 如果我从 mail@xyz.com 发送,那么在我的错误情况下,消息 ID 应该是 ,我得到的消息 ID 为 应该是
  • 有时您的主机提供商有邮件渠道。这会改变您的邮件系统
  • 不得不提的是,您不必担心这一点,这只是您的托管服务提供商的服务器配置,邮件通道帮助服务器提供商不要阻止他们的客户域并保护在垃圾邮件黑名单。
  • 难道你们都认为这确实是 phpmailer 本身的,就像看到这个来自 phpmailer.php $DKIMquery = 'dns/txt'; 的代码的 sn-p //查询方法 $DKIMtime = time(); //总是在不被询问的情况下签署这些标题 //推荐列表来自tools.ietf.org/html/rfc6376#section-5.4.1 $autoSignHeaders = [ 'from', 'to', 'cc', 'date', 'subject', 'reply-to', 'message- id'、'content-type'、'mime-version'、

标签: php smtp gmail phpmailer


【解决方案1】:

根据我的经验,如果要设置 MessageID,则不需要使用 addCustomHeader。

假设您想将 Message ID 设置为 [random]@send.alok,那么请使用以下内容:

$mail->MessageID = "<" . md5('HELLO'.(idate("U")-1000000000).uniqid()).'@send.alok>';

因此,请执行以下操作:

<?php
use PHPMailer\PHPMailer\PHPMailer; 
use PHPMailer\PHPMailer\Exception; 

require './Exception.php'; 
require './PHPMailer.php'; 
require './SMTP.php'; 



$user='smtp_xxxxxx_user';
$pass='smtp_password';
$mail = new PHPMailer(true);                              

try { 

    $mail->CharSet ="UTF-8";       
    $mail->SMTPDebug = 0;                      
    $mail->isSMTP();                             
    $mail->Host = 'smtp.xxxxx.com';        

    $mail->Username = $user;               
    $mail->Password = $pass;             


$mail->MessageID = "<" . md5('HELLO'.(idate("U")-1000000000).uniqid()).'@send.alok>';


  $mail->setFrom('jon@alxxxx.com', 'Jon Al');  
  $mail->addAddress('jon@gmail.com');  

$subject="test";
$message="test123";

    $mail->Port = 25;                             
    $mail->isHTML(true);                                  
    $mail->Subject = $subject;
    $mail->Body    = $message;
    $mail->send(); 
//    echo 'Success'; 
} catch (Exception $e) { 
//echo 'Failed'; 
}

?>

您可以参考下面的屏幕转储了解结果

【讨论】:

    猜你喜欢
    • 2017-10-18
    • 1970-01-01
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    相关资源
    最近更新 更多