Home » Php » email – PHP mail() – How to set Priority?

email – PHP mail() – How to set Priority?

Posted by: admin April 23, 2020 Leave a comment

Questions:

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.

By priority, I mean High, Normal, Low or 1, 2, 3 in the headers. So the recipient knows the urgency of the mail.

Thank you!

How to&Answers:

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).

See the following example (taken from php’s 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);
?> 

Answer:

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

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

Answer:

Call it with the X-Priority header in the 4th parameter:

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

Answer:

A comment on the PHP mail function documentation said:

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

Answer:

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

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

Answer:

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.