PHP mail() - 如何设置优先级?

时间:2010-11-12 22:24:11

标签: php email

有没有办法设置PHP mail()的优先级?我查看了在线手册,但我找不到任何参考。

优先级,我的意思是标题中的高,正常,低或1,2,3。所以收件人知道邮件的紧急程度。

谢谢!

6 个答案:

答案 0 :(得分:58)

通常通过在标题中设置以下字段来完成:

  • “X-Priority”(值:从最高[1]到最低[5]的1到5),
  • “X-MSMail-Priority”(值:高,正常或低),
  • “重要性”(值:高,正常或低)。

请参阅以下示例(摘自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);
?> 

答案 1 :(得分:7)

<?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); 
?>

来自:http://www.php.net/manual/en/function.mail.php#91058

答案 2 :(得分:2)

使用第4个参数中的X-Priority标头调用它:

mail ( $to, $subject, $message , "X-Priority: 1")

答案 3 :(得分:1)

A comment上的{p> PHP mail function documentation说:

<?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);

答案 4 :(得分:0)

要定义邮件优先级,您必须将这些行放在标题中:

<?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); 
?> 

http://php.net/manual/en/function.mail.php

答案 5 :(得分:0)

除了我的问题之外,其他所有操作均不起作用

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

PS:电子邮件正文必须在标题之前。