对于任何寻找有效方法的人:点击 @ErikNedwidek 留下的链接将引导您看到这篇博文:http://www.sensefulsolutions.com/2010/08/how-does-email-threading-work-in-gmail.html http://www.sensefulsolutions.com/2010/08/how-does-email-threading-work-in-gmail.html
指定了两条规则:
- 主题必须相似。
- 发送者必须是线程的一部分或者必须使用回复。
第一个被覆盖,因为主题是相同的,并且第二个的第一部分应该被覆盖,因为发送者与接收者相同。
还有这一部分:
值得注意的一件有趣的事情是,如果您从 Gmail 发送电子邮件,它们也会被线程化。除了一个小细节外,规则与您收到规则时完全相同。如果您在没有主题前缀的情况下发送相同的消息两次(例如,主题是 test 而不是 re: test),它确实会在接收端线程化,但不会在发送端线程化。相反,如果它确实包含前缀(例如 re: test),则在这两种情况下都会将其线程化。
我认为它没有被线程化,因为发送者和接收者地址是相同的。将接收者地址更改为另一个测试地址意味着消息在接收时可以正确线程化。保持发送者和接收者地址相同,但添加另一个接收者地址也意味着它们可以正确连接。不过,仅拥有一个与发件人地址相匹配的收件人地址是行不通的。
我尝试在主题的开头添加“re:”,但这没有任何区别。然而,有效的是使用以下命令添加“In-Reply-To”标头:
$mail->addCustomHeader( 'In-Reply-To', '<' . SUPPORT_EMAIL . '>' );
请注意,<
and >
很重要,因为没有它似乎会被忽视。
总结一下:
-
[email protected] /cdn-cgi/l/email-protection
发送至[email protected] /cdn-cgi/l/email-protection
= 无螺纹
-
[email protected] /cdn-cgi/l/email-protection
发送至[email protected] /cdn-cgi/l/email-protection
= 螺纹加工
-
[email protected] /cdn-cgi/l/email-protection
发送至[email protected] /cdn-cgi/l/email-protection
and [email protected] /cdn-cgi/l/email-protection
= 两者都有螺纹
-
[email protected] /cdn-cgi/l/email-protection
发送至[email protected] /cdn-cgi/l/email-protection
with re:
放在主题前面 = 无线程
-
[email protected] /cdn-cgi/l/email-protection
发送至[email protected] /cdn-cgi/l/email-protection
带标题In-Reply-To
set to [email protected] /cdn-cgi/l/email-protection
= 无螺纹
-
[email protected] /cdn-cgi/l/email-protection
发送至[email protected] /cdn-cgi/l/email-protection
带标题In-Reply-To
set to <[email protected] /cdn-cgi/l/email-protection>
= 螺纹加工
完整的 PHPMailer 代码:
$mail = new PHPMailer; // create a new instance
$mail->isSMTP(); // set that we're using stmp
$mail->CharSet = 'UTF-8'; // make sure it's utf-8 encoded
$mail->Host = 'smtp.gmail.com'; // the hostname of the mail server
$mail->Port = 587; // set the smtp port number (587 for authenticated TLS)
$mail->SMTPSecure = 'tls'; // set the encryption to use, ssl (deprecated) or tls
$mail->SMTPAuth = true; // should we use smtp authentication?
$mail->Username = MY_EMAIL_LOGIN; // the user name for the smtp authentication
$mail->Password = MY_EMAIL_PASSWORD; // the password for smtp authentication
$mail->wordWrap = 70; // make sure we've no lines longer than 70 chars
$mail->Subject = "[Payment] Player {$payment->user->name} ({$payment->user->id}) - Payment ID {$payment->id}";
$mail->Body = $htmlBody; // our html body
$mail->AltBody = $plainBody; // our fallback, plain-text body
$mail->setFrom( SUPPORT_EMAIL, 'Support' ); // who this is from
$mail->addReplyTo( SUPPORT_EMAIL, 'Support' ); // who we can reply to
$mail->addAddress( SUPPORT_EMAIL ); // who we're sending it to
$mail->addCustomHeader( 'In-Reply-To', '<' . SUPPORT_EMAIL . '>' ); // so we get threading on gmail (needed as to and from are the same address)
$mail->isHTML( true ); // is this a html formatted email?
if( !$mail->send() )
error_log( "[paymentsRealtimeUpdates] Can't send an email to support about payment {$payment->id} for user {$payment->user->id}" );
不相关的小点-无论你为该设置什么地址setFrom
似乎被忽略了 - Gmail 会采用后面的任何地址MY_EMAIL_LOGIN
login.