Sending e-mails
Laravel's Mail
class extends the popular Swift Mailer package, which makes sending e-mails a breeze. The e-mail templates are loaded in the same way as views, which means you can use the Blade syntax and inject data into your templates:
- To inject some data into a template located inside
resources/views/email/view.blade.php
, we use the following function:Mail::send('email.view', $data, function($message) {});
- To send both an HTML and a plain text version, we use the following function:
Mail::send(array('html.view', 'text.view'), $data, $callback);
- To delay the e-mail by 5 minutes (this requires a queue), we use the following function:
Mail::later(5, 'email.view', $data, function($message) {});
Inside the $callback
closure that receives ...
Get Laravel 5 Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.