有没有办法设置PHP mail()的优先级?我查看了在线手册,但找不到任何相关内容。
所谓优先级,是指在邮件头中使用高、中、低或1、2、3等级别,以便收件人了解邮件的紧急程度。
谢谢!
通常通过设置以下标题字段来完成:
请参见以下示例(摘自php的邮件函数文档):
<?php
$headers = "MIME-Version: 1.0\n" ;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$status = mail($to, $subject, $message,$headers);
?>
Priority
而不是 X-Priority
。 - Xenos\n
是换行的最佳方式,我们不应该需要两个字符来表示 \r\n
。 - mbomb007Priority
和X-Priority
是两个完全不同的概念。虽然X-Priority
是一种供应商特定的非标准扩展(因此有“X-”),但Priority
旨在告诉MTA在传输期间优先处理邮件,我猜大多数情况下都会被忽略。 Importance
是唯一可以标记邮件为用户高优先级的标准标题。 - Bachsau<?php
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$status = mail($to, $subject, $message, $headers);
?>
在第四个参数中使用 X-Priority 标头进行调用:
mail ( $to, $subject, $message , "X-Priority: 1")
X-priority:2
,所以在实际应用中我不会添加任何内容。当然我会将其保存为一个常量。 - AndreKR要定义邮件优先级,您需要在邮件头中添加以下行:
<?php
$headers = "MIME-Version: 1.0\n" ;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$status = mail($to, $subject, $message,$headers);
?>
除了这个,其他都对我的问题没有用。
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: xyz@example.com' . "\r\n";
$headers .= 'Cc: Admin@example.com' . "\r\n";
注意:电子邮件正文必须在头部之前。
Priority:
标头的不同用法,这会导致某些邮件客户端以红色感叹号等方式呈现消息? - VoteyDisciple