Laravel Mailable: The new and improved way to send email in Laravel
Laravel Tutorials / updated: March 27, 2017

Laravel Mailable: The new and improved way to send email in Laravel

A new feature in Laravel 5.3 is a way to simplify sending email by creating “mailable” classes that handle setting up your emails.

The best way to explain this feature is with an example. In Laravel 5.2 you would typically send an email like the following that is outlined in the documentation:

Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
    $m->from('', 'Your Application');
    $m->to($user->email, $user->name)->subject('Your Reminder!');

A lot is going on in those four lines of code. You pass a view, data to assign to the view, use the “user” in the closure, and finally setup your message.

Now in Laravel 5.3 you can simplify this by utilizing a “mailable” class.

php artisan make:mail YourReminder

Next, open the new class that is created and all of a mailable configuration is done in the build method. Within this, you may call various methods such as from, subject, view, and attach to configure the email’s presentation and delivery. Here is a minimal example:

public function build()
    return $this->from('')

Now, anytime you want to send this email you can call it like this:

Mail::to($email)->send(new YourReminder);

All of the existing mail features still work. You can queue, add cc, bcc, attach files and more.

If you’d like to learn more about Laravel Mailable here are a few resources to help you on your journey:

Laravel News Partners


Join the weekly newsletter and never miss out on new tips, tutorials, and more.