Laravel/PHP Articles

Articles from Laravel/PHP sites on the web

Laravel/PHP Articles
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( 'mail@mail.com' )->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 :-)

Sign Up For Our Newsletter

Each Week, We curate the top Laravel/PHP articles, jobs, events and More!

We'll send you a weekly email with the latest Laravel/PHP articles, jobs and events. Please review our Code of Conduct in the meantime. Talk to you soon!