Laravel Mail facade is an abstraction over SwiftMailer. Not sure of the exact syntax but you should be able to figure it out, here’s a link: https://swiftmailer.symfony.com/docs/messages.html#setting-the-message-priority
May 31, 2020
4
Level 1
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);
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.