Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Email Headers in Laravel 4

I can't seem to locate the method within the Laravel 4 docs/Email API where I can add custom headers to an email.

For example:

Mail::send('emails.welcome', $data, function($message)
{
    $message->to('[email protected]', 'John Smith')->subject('Welcome!');
    $message->headers('X-Tags', 'tag1 tag2 tag3');
});

Does anyone know how this can be done?

like image 721
eski009 Avatar asked Jul 04 '13 08:07

eski009


1 Answers

As far as I know there's no way to add custom headers without reaching in to Swift Mailer.

Try something like this.

$message->getSwiftMessage()->getHeaders()->addTextHeader('X-Tags', 'tag1 tag2 tag3');

It doesn't look pretty but from looking through the source that should do the trick.


As pointed out in the comments below the getSwiftMessage method isn't required as there is an __call magic method on the Illuminate\Mail\Message class that I overlooked.

$message->getHeaders()->addTextHeader('X-Tags', 'tag1 tag2 tag3');
like image 133
Jason Lewis Avatar answered Sep 28 '22 06:09

Jason Lewis