Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Mailable Headers

I have this issue and is that I need to set header to a Mail but not via Mail::send() I need to set the headers inside the Mailable Class that I created with php artisan make:mail

Thanks a lot.

I'm using Laravel 5.3

like image 917
dacastro4 Avatar asked Jan 06 '17 23:01

dacastro4


1 Answers

You should be able to use the withSwiftMessage method inside your mailable. You can pass this method a callback which receives the Swift_Message instance which you can use to set your headers.

In your build method you could have:

$this->withSwiftMessage(function ($message) {
    $headers = $message->getHeaders();
    $headers->addTextHeader('header-name', 'optional-value');
});

Hope this helps!

like image 52
Rwd Avatar answered Sep 17 '22 19:09

Rwd