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 the message object, we can call the following methods to alter the message that is to be sent:
$message->subject('Welcome to the Jungle');
$message->from('email@example.com', &apos...