PHPMailer&;Gmail会话视图
我正在使用PHPMailer发送电子邮件,以支持我们的服务器ping更新(通常与付款相关) 我正在尝试将相关电子邮件显示为Gmail对话,以便于支持员工跟踪以前的更新/回复。我原本以为这是基于主题的,但这似乎没有什么区别 我的邮件代码:PHPMailer&;Gmail会话视图,php,email,phpmailer,Php,Email,Phpmailer,我正在使用PHPMailer发送电子邮件,以支持我们的服务器ping更新(通常与付款相关) 我正在尝试将相关电子邮件显示为Gmail对话,以便于支持员工跟踪以前的更新/回复。我原本以为这是基于主题的,但这似乎没有什么区别 我的邮件代码: $mail = new PHPMailer; // create a new instance $mail->isSMTP();
$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留下的链接,您将看到这篇博文: 规定了两条规则:
- 主题必须相似李>
- 发送方必须是线程的一部分,或者必须使用作为回复的发送方
$mail->addCustomHeader( 'In-Reply-To', '<' . SUPPORT_EMAIL . '>' );
不相关的小问题-无论您为
setFrom
设置了什么地址,似乎都被忽略了-Gmail将接受MY\u EMAIL\u LOGIN
LOGIN后面的任何地址。是的。这让我发疯(在我正在编写的C#应用程序中)。只需设置“回复”标题就可以了。我喜欢你记录一切的方式。您是开发人员:-)