Category: Laravel

I recently upgraded my app to Laravel 5.8 and one of the reasons I did it so soon this time was the mail driver support for Postmark.
In case you don't know Postmark, it's a great service that helps a lot with transactional emailing.
Postmark has a way of adding a Tag to a message and/or special meta content so you can do interesting stuff with it's API.
But how can we add those to the Mailable flow of Laravel?
I created a trait that looks like thisAnd then in any Mailable class I only set the "Tag" or "Meta"$mailable = new myMailable(); $mailable->setTag( 'Tag' ); $mailable->setMeta([ 'id' => 123 ]); Mail::to( '' )->send($mailable);and of course chain that to the mailable flow by using the Trait:class myMailable extends Mailable { use Postmarkable ; public function build () { return $this ->addPostmarkHeaders()->subject( 'My subject' )->markdown( 'markdownfile' ); } }And that's it :-)

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Community Partners