Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set urgent option in phpmailer

Tags:

php

phpmailer

How can I sent an mail with phpmailer with the option urgent set like in MS Outlook?

like image 619
Muiter Avatar asked May 26 '12 13:05

Muiter


2 Answers

This is done by adding importance and priority headers to the outbound email. MS Outlook uses a particular one of its own, while most other mail clients use Importance or Priority. Add them with PHPMailer via the AddCustomHeader() method and the $Priority property.

// 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");

Note that mail clients are free to not implement/ignore these headers, so you can't fully rely on them. Also, many spam filters will use them as a red flag for identifying spam. Use them with caution.

Official documentation:

PHPMailer Properties

PHPMailer Methods

like image 196
Michael Berkowski Avatar answered Oct 05 '22 11:10

Michael Berkowski


Supplement:

That work´s fine, but some SPAM Filter will use the Priority Configuration (doesn´t matters which Priority is set) to filter in SPAM.

And php Mailer will set the Priority Flag ALWAYS. (Default to 3)

So in MY php Mailer class i´d commentet the line

$this->HeaderLine('X-Priority', $this->Priority);

Maybe a solution like:

class.phpmailer.php

if($this->Priority > 0) $this->HeaderLine('X-Priority', $this->Priority);

And in your php script something like this:

$yourMessage->Priority = 0;

Makes it a bit configurable

like image 39
ChristianNRW Avatar answered Oct 05 '22 10:10

ChristianNRW