Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LadyDeathKZN's avatar

Mail Importance

Hi, I have been asked to add a priority to emails, letting the receiver know that they need attention immediately. how would one do this in Laravel? Is there already a system in place for this or does one need to do it manually?

This is my mailable

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class UserCreated extends Mailable
{
    use Queueable, SerializesModels;
    public $data;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from('[email protected]')->subject('New User Added')->markdown('emails.userCreated');
    }
}

This is an article I have found and have no idea how to implement this if one is to set it manually. https://ziplineinteractive.com/blog/how-to-set-email-priority-to-high-or-highest-with-php-mail/

//BUILD EMAIL HEADERS
$headers  = "From: Some Person <[email protected]>\n";
$headers .= "Reply-To: [email protected]\n";
$headers .= "Return-Path: [email protected]\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";

//SET EMAIL PRIORITY
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";

//SEND EMAIL
mail("[email protected]","Subject","Body",$headers);
0 likes
4 replies
LadyDeathKZN's avatar

Hi :). Thanks for the info, I tried the setPriority(1), in both the mailable and the mail option in the controller and it through out an error saying setPriority() does not exist on that class. I do think Laravel should investigate this and add it to the framework it would be very useful

Brian Kidd's avatar
Level 27

You can get a reference to the SwiftMessage in the mailable like this:

public function build()
{
  return $this->withSwiftMessage(function ($message) {
    $message->setPriority(\Swift_Message::PRIORITY_HIGH);
  })-> ... do other stuff;
}
1 like

Please or to participate in this conversation.