Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Laravel 5 Essentials

You're reading from   Laravel 5 Essentials Explore the fundamentals of Laravel, one of the most expressive and robust PHP frameworks available

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher Packt
ISBN-13 9781785283017
Length 144 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Martin Bean Martin Bean
Author Profile Icon Martin Bean
Martin Bean
Arrow right icon
View More author details
Toc

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image