如何使用phpmailer发送邮件,并像在MS Outlook中那样设置紧急选项?
这是通过向出站电子邮件添加重要性和优先级标头来完成的。 MS Outlook使用自己的特定邮件客户端,而大多数其他邮件客户端使用Importance
或Priority
。 使用 PHPMailer 通过 AddCustomHeader()
方法和 $Priority
属性添加它们。
// For most clients expecting the Priority header:
// 1 = High, 2 = Medium, 3 = Low
$yourMessage->Priority = 1;
// MS Outlook custom header
// May set to "Urgent" or "Highest" rather than "High"
$yourMessage->AddCustomHeader("X-MSMail-Priority: High");
// Not sure if Priority will also set the Importance header:
$yourMessage->AddCustomHeader("Importance: High");
请注意,邮件客户端可以自由地不实现/忽略这些标头,因此您不能完全依赖它们。 此外,许多垃圾邮件过滤器会将它们用作识别垃圾邮件的危险信号。 请谨慎使用它们。
官方文档:
PHPMailer 属性
PHPMailer 方法
补充:
这项工作很好,但是某些垃圾邮件过滤器将使用优先级配置(设置哪个优先级无关紧要)来过滤垃圾邮件。
php Mailer将始终设置优先级标志。(默认为 3)
所以在我的 php Mailer 类中,我会评论这条线
$this->HeaderLine('X-Priority', $this->Priority);
也许像这样的解决方案:
class.phpmailer.php
if($this->Priority > 0) $this->HeaderLine('X-Priority', $this->Priority);
在你的 php 脚本中,像这样:
$yourMessage->Priority = 0;
使其有点可配置