PHPMailer&;Gmail会话视图

PHPMailer&;Gmail会话视图,php,email,phpmailer,Php,Email,Phpmailer,我正在使用PHPMailer发送电子邮件,以支持我们的服务器ping更新(通常与付款相关) 我正在尝试将相关电子邮件显示为Gmail对话,以便于支持员工跟踪以前的更新/回复。我原本以为这是基于主题的,但这似乎没有什么区别 我的邮件代码: $mail = new PHPMailer; // create a new instance $mail->isSMTP();

我正在使用PHPMailer发送电子邮件,以支持我们的服务器ping更新(通常与付款相关)

我正在尝试将相关电子邮件显示为Gmail对话,以便于支持员工跟踪以前的更新/回复。我原本以为这是基于主题的,但这似乎没有什么区别

我的邮件代码:

$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->isHTML( true );                                      // is this a html formatted email?
if( !$mail->send() )
    error_log( "Can't send an email to support about payment {$payment->id} for user {$payment->user->id}" );
$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}" );
如果我收到两封来自同一用户的关于同一笔付款的电子邮件(所以是同一主题),我希望它以以下形式出现:

+-----------------------------------------------------------------------------+
| Support (2)       | [Payment] Player foo (123456789) - Payment ID 123456789 |
+-----------------------------------------------------------------------------+
它实际上是以以下形式出现的:

+-----------------------------------------------------------------------------+
| Support           | [Payment] Player foo (123456789) - Payment ID 123456789 |
+-----------------------------------------------------------------------------+
| Support           | [Payment] Player foo (123456789) - Payment ID 123456789 |
+-----------------------------------------------------------------------------+

我遗漏了一些简单的东西吗?

好吧,这与PHP没有任何关系。这与Gmail将电子邮件嵌套在“对话”中的方式有关


您可能想看看类似以下问题的答案:


作者在一篇博客文章中也有更多的信息。它已经3年了,但希望信息仍然有效。

对于任何寻找有效信息的人来说:点击@ErikNedwidek留下的链接,您将看到这篇博文:

规定了两条规则:

  • 主题必须相似
  • 发送方必须是线程的一部分,或者必须使用作为回复的发送方
第一部分被涵盖,因为主题是相同的,第二部分的第一部分应该被涵盖,因为发送者和接收者是相同的

还有这一部分:

值得注意的一件有趣的事情是,如果你从Gmail发送电子邮件,它们也会被线程化。这些规则与您收到它们时完全相同,只是有一个小细节。如果您两次发送相同的消息,但没有主题前缀(例如,主题是test而不是re:test),则它确实会在接收端线程化,但不会在发送端线程化。相反,如果它确实包含前缀(例如re:test),则在这两种情况下都将对其进行线程化

我认为它没有线程化,因为发送方和接收方地址是相同的。将接收器地址更改为另一个测试地址意味着消息在接收时被正确线程化。保持发送者和接收者地址相同,但添加另一个接收者地址也意味着它们得到了正确的线程。但是,仅仅拥有一个与发送者地址匹配的接收者地址是行不通的

我试着在主题的开头加上一个“re:”,但没有任何区别。然而,有效的方法是使用以下方法添加“回复”标题:

$mail->addCustomHeader( 'In-Reply-To', '<' . SUPPORT_EMAIL . '>' );

不相关的小问题-无论您为
setFrom
设置了什么地址,似乎都被忽略了-Gmail将接受
MY\u EMAIL\u LOGIN
LOGIN后面的任何地址。

是的。这让我发疯(在我正在编写的C#应用程序中)。只需设置“回复”标题就可以了。我喜欢你记录一切的方式。您是开发人员:-)