06.10.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Mail 405<br />

Universal To<br />

Another solution provided by Laravel is to set a universal recipient of all e-mails sent by the<br />

framework. This way, all the emails generated by your application will be sent to a specific address,<br />

instead of the address actually specified when sending the message. This can be done via the to<br />

option in your config/mail.php configuration file:<br />

1 'to' => [<br />

2 'address' => 'dev@domain.com',<br />

3 'name' => 'Dev Example'<br />

4 ],<br />

Mailtrap<br />

Finally, you may use a service like Mailtrap¹⁹⁰ and the smtp driver to send your e-mail messages to a<br />

“dummy” mailbox where you may view them in a true e-mail client. This approach has the benefit<br />

of allowing you to actually inspect the final e-mails in Mailtrap’s message viewer.<br />

Events<br />

Laravel fires an event just before sending mail messages. Remember, this event is fired when the mail<br />

is sent, not when it is queued. You may register an event listener in your EventServiceProvider:<br />

1 /**<br />

2 * The event listener mappings for the application.<br />

3 *<br />

4 * @var array<br />

5 */<br />

6 protected $listen = [<br />

7 'Illuminate\Mail\Events\MessageSending' => [<br />

8 'App\Listeners\LogSentMessage',<br />

9 ],<br />

10 ];<br />

¹⁹⁰https://mailtrap.io

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!