- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我们的服务器收到更新(通常与付款相关)时,我正在使用 PHPMailer 发送电子邮件以提供支持。
我正在尝试让相关电子邮件显示为 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}" );
如果我收到来自同一用户的 2 封电子邮件,涉及同一笔付款(因此是同一主题),我希望它以以下形式出现:
+-----------------------------------------------------------------------------+
| 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 |
+-----------------------------------------------------------------------------+
我是不是漏掉了一些简单的东西?
最佳答案
对于寻找有效方法的任何人:点击@ErikNedwidek 留下的链接将带您到这篇博文:http://www.sensefulsolutions.com/2010/08/how-does-email-threading-work-in-gmail.html
指定了两条规则:
第一个被覆盖,因为主题相同,第二个的第一部分应该被覆盖,因为发送者与接收者相同。
还有这部分:
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.
我认为它没有被线程化,因为发送者和接收者地址相同。将接收方地址更改为另一个测试地址意味着消息在收到时已正确串接。保持发送方和接收方地址相同,但添加另一个接收方地址也意味着它们得到了正确的线程化。不过,只有一个与发件人地址匹配的收件人地址是行不通的。
我尝试在主题的开头添加一个“re:”,但这没有任何区别。然而,起作用的是使用以下方法添加“In-Reply-To” header :
$mail->addCustomHeader( 'In-Reply-To', '<' . SUPPORT_EMAIL . '>' );
请注意 <
和 >
很重要,因为没有它似乎被忽略了。
总结一下:
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
发送至 foo@domain.com
带标题 In-Reply-To
设置为 foo@domain.com
= 无线程foo@domain.com
发送至 foo@domain.com
带标题 In-Reply-To
设置为 <foo@domain.com>
=线程完整的 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
后面的任何地址登录。
关于PHPMailer 和 Gmail 对话 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22639839/
如何安装 phpMailer在共享托管环境中?我需要将其用于用户的电子邮件验证和密码更改。 最佳答案 您可以在这里下载:https://github.com/PHPMailer/PHPMailer 将
当我使用 phpmailer 通过 Gmail 发送时,电子邮件需要很长时间才能发送,而且有时发送不成功。我正在使用 XAMPP 作为本地主机。 这是我的代码: if($_POST['submit']
我正在使用 PHPMailer 发送一些简单的电子邮件,但是函数 SetFrom() 似乎不起作用,即使我使用的代码直接来自 phpmails 文档 ( http://phpmailer.worxwa
使用 PHP 邮件程序 6.0.6 版 我知道类似的问题得到了回答,但我的情况不同。 我已经成功配置了它运行良好的脚本;我正在接收邮件,然后突然之间没有任何变化,它开始向我抛出这个错误。 错误
我可以生成 pdf 以便轻松查看和下载。我正在尝试发送一封附有 pdf 的电子邮件。我已经连续几天浏览谷歌了几个小时,没有什么比这个链接更让我更接近了,sending an email attachm
我可以生成 pdf 以便轻松查看和下载。我正在尝试发送一封附有 pdf 的电子邮件。我已经连续几天浏览谷歌了几个小时,没有什么比这个链接更让我更接近了,sending an email attachm
由于错误,我无法收到确认电子邮件。这是我的 PhpMailer 错误。 fatal error :未捕获错误:在 C:\xampp\htdocs\Web\PHPMailer\PHPMailer.php
这个问题在这里已经有了答案: SMTP connect() failed PHPmailer - PHP (17 个答案) 关闭 7 年前。 这是我在网上引用了很多之后从本地主机发送电子邮件的代码。
我写了一个 PHP 脚本,可以发送邮件。我从“mail@something.com”发送它们并将“返回路径”设置为“bounce@something.com”,但我仍然收到退回邮件到发件人邮件(“ma
我使用 php curl() 函数从服务器 A 连接到邮件服务器 B 以发送邮件。 $body = "body\n\nmore body\nmore body\n\nmore body\n\n"; $
PHPMailer 只是在发送电子邮件时挂起。我逐行注释了所有代码,一切正常,直到到达 如果(!$邮件->发送()) 此时页面进入旋转状态 - 没有错误消息或任何其他错误指示。我想我拥有所有必需的
我在问这里之前阅读了一些其他问题,因为其他答案没有回应我的问题。 我有一个用 php 定制的 cms。例如,如果我插入一个新的付款,脚本会向所有管理员用户发送一个通知: function insert
我用 Ubuntu 和 DigitalOcean 构建了一个 droplet,我正在尝试将它配置为使用 SMTP 发送电子邮件。 我知道 DigitalOcean 通过 IPv6 而不是通过 IPv4
我是 PHP 的新手。我从这里下载了一个 phpmailer 脚本(带有文件)-> phpmailer 我正在使用 XAMPP,我将文件定位在: \htdocs\QMS\phpmailer 我的 ph
我这里有一个大问题! 我需要向所有订阅者发送时事通讯(大约 1200) 问题是它只将时事通讯发送给其中的 150-180。 我有一个在 php 中实现的脚本,它使用 PhpMailer() 类将时事通
是否可以使用phpmailer发送异步电子邮件? 常规邮件发送代码段如下: $mail->Send(); PHP在继续之前等待Send()返回结果。是否有可能使phpmailer立即返回结果,而无需等
我有这样一种情况,我发送了两封不同的电子邮件,一封给客户,另一封在成员接受任务后发送给成员。在函数中我调用了 2 个函数,一个发送给客户端,一个发送给成员。发生的情况是第二封电子邮件同时发送给成员(m
我正在使用 PHPMailer在我的网站上,但它返回一个错误: 您必须提供至少一个收件人电子邮件地址。 服务器正在运行 PHP 7。我查看了以下页面以寻找答案: PHP Mailer You must
我正在尝试配置 PHPMailer 我上传了 1 个文件,它是 class.phpmailer.php 并创建了另一个包含以下内容的 php 文件: IsSMTP(); // enable SMTP
使用 PHPMailer 向我的 Gmail 帐户发送电子邮件后,单击“邮件发送者”右侧的“显示详细信息”后,它会显示“yourhostingaccount.com”。这是一张图片: 我读过您可以使用
我是一名优秀的程序员,十分优秀!