PHP mail() - 如何设置优先级?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4169605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP mail() - How to set Priority?
提问by tanjir
Is there any way to set the priority of PHP mail()? I looked at the online manual but I can't find any reference to it.
有没有办法设置PHP mail()的优先级?我查看了在线手册,但找不到任何参考。
By priority, I mean High, Normal, Low or 1, 2, 3 in the headers. So the recipient knows the urgency of the mail.
优先级是指标题中的高、正常、低或 1、2、3。所以收件人知道邮件的紧急程度。
Thank you!
谢谢!
回答by tanjir
That's usually done by setting following fields in the header:
这通常通过在标题中设置以下字段来完成:
- "X-Priority" (values: 1 to 5- from the highest[1] to lowest[5]),
- "X-MSMail-Priority" (values: High, Normal, or Low),
- "Importance" (values: High, Normal, or Low).
- “X-Priority”(值:1 到 5-从最高 [1] 到最低 [5]),
- “X-MSMail-Priority”(值:高、正常或低),
- “重要性”(值:高、正常或低)。
See the following example (taken from php's mail function documentation):
看下面的例子(取自 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);
?>
回答by Evan Mulawski
<?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);
?>
回答by AndreKR
Call it with the X-Priority header in the 4th parameter:
使用第 4 个参数中的 X-Priority 标头调用它:
mail ( $to, $subject, $message , "X-Priority: 1")
回答by Pascal Qyy
A commenton the PHP mail function documentationsaid:
注释上的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);
回答by zod
To define a mail priority you have to put this lines in the headers:
要定义邮件优先级,您必须将此行放在标题中:
<?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);
?>
回答by vaishu
everything didn't work except this for my problem
除了这个因为我的问题,一切都不起作用
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: [email protected]' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
PS: email body must before the headers.
PS:电子邮件正文必须在标题之前。