PHPMailer&Gmail对话检视 [英] PHPMailer & Gmail conversation view

查看:62
本文介绍了PHPMailer&Gmail对话检视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHPMailer发送电子邮件以支持我们的服务器对更新进行ping操作(通常与付款有关).

I'm using PHPMailer to send emails to support when our server is pinged with updates (usually related to payments).

我正试图使相关电子邮件显示为Gmail对话,以使支持人员更容易地跟踪以前的更新/回复.我最初以为它是基于主题的,但这似乎没有什么不同.

I'm trying to get related emails to display as a Gmail conversation to make it easier to support staff to follow previous updates/replies. I had originally assumed that it was based on subject, but that doesn't seem to make a difference.

我的邮递区号:

$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}" );

如果我从同一位用户那里收到2封电子邮件,涉及同一笔付款(所以​​是同一主题),那么我希望它的发送方式是:

If I get 2 emails from the same user relating to the same payment (so the same subject), what I want it to come in as:

+-----------------------------------------------------------------------------+
| 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 |
+-----------------------------------------------------------------------------+

我想念一些简单的东西吗?

Am I missing something simple?

推荐答案

对于任何寻求成功的人:按照@ErikNedwidek留下的链接,您将进入以下博客文章:

For anybody looking for what worked: following the link left by @ErikNedwidek will lead you to this blog post: http://www.sensefulsolutions.com/2010/08/how-does-email-threading-work-in-gmail.html

指定了两个规则:

  • 主题必须相似.
  • 发件人必须是线程的一部分,或者必须使用in-reply-to.

因为主题是相同的,所以第一个被覆盖了,而第二个的第一部分应该被覆盖了,因为发送者和接收者是相同的.

The first one is covered, as the subjects are identical, and the first part of the second should be covered as the sender is the same as the receiver.

也有这部分:

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

One interesting thing to note is that if you send email messages from Gmail they will also be threaded. The rules are exactly the same as when you receive them, except for one minor detail. If you send the same exact message twice with no subject prefix (e.g. subject is test not re: test) it does get threaded on the receiving end, but not on sending end. Conversely, if it does contain a prefix (e.g. re: test) it will be threaded in both cases.

我发现它没有被线程化,因为发送者和接收者的地址是相同的.将接收者地址更改为另一个测试地址意味着在接收到消息时正确地对其进行了线程处理.保持发送者和接收者的地址相同,但是添加另一个接收者的地址也意味着它们正确地进行了线程化.但是,只有一个与发送者地址匹配的接收者地址是行不通的.

I figured it wasn't getting threaded because the sender and receiver addresses are the same. Changing the receiver address to another test address meant that messages were threaded properly when received. Keeping the sender and receiver address the same, but adding another receiver address also meant that they got threaded properly. Just having one receiver address that matches the sender address wouldn't work though.

我尝试在主题的开头添加"re:",但这没有任何区别.但是,有效的方法是使用以下命令添加"In-Reply-To"标头:

I tried adding a 're:' to the start of the subject, but that didn't make any difference. What did work however, was adding the 'In-Reply-To' header using:

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

请注意,< > 很重要,因为没有它似乎会被忽略.

Note that the < and > are important, as without it seemed to be ignored.

总结一下:

  • foo@domain.com 发送到 foo@domain.com =无线程
  • foo@domain.com 发送到 bar@domain.com =线程
  • foo@domain.com 发送到 foo@domain.com bar@domain.com =两者都穿线
  • foo@domain.com 发送至 foo@domain.com 并带有 re:主题之前=无线程
  • foo@domain.com 发送至标头 In-Reply-To 设置为 foo @的 foo@domain.com domain.com =无线程
  • foo@domain.com 发送至 foo@domain.com ,且标头 In-Reply-To 设置为<foo@domain.com> =线程
  • foo@domain.com sending to foo@domain.com = no threading
  • foo@domain.com sending to bar@domain.com = threading
  • foo@domain.com sending to foo@domain.com and bar@domain.com = threading on both
  • foo@domain.com sending to foo@domain.com with re: pre-pended to the subject = no threading
  • foo@domain.com sending to foo@domain.com with header In-Reply-To set to foo@domain.com = no threading
  • foo@domain.com sending to foo@domain.com with header In-Reply-To set to <foo@domain.com> = threading

完整的PHPMailer代码:

Full PHPMailer code:

$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 登录名后面的任何地址.

Unrelated small point - whatever address you set for the setFrom seemed to be ignored - Gmail would take whatever address is behind the MY_EMAIL_LOGIN login.

这篇关于PHPMailer&amp;Gmail对话检视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆