In Laravel 5.5 You Can Render Mailables to the Browser

In Laravel 5.5 You Can Render Mailables to the Browser

When you are building custom HTML email templates, it’s typically a chore to test them across all the email clients, and testing them over and over. There are a few tools like Litmus which help solve this problem, but the service is expensive.

Another way to test while you are developing is to render out the email to the browser so you can make quick changes and get almost instant feedback. Although this is a practical use case, rendering Mailables to the browser hasn’t been that simple. That is changing in Laravel 5.5 and these will implement the Renderable Contract allowing you to display them directly from a route.

For example let’s create a UserWelcome Mailable:

php artisan make:mail UserWelcome --markdown=emails.user.welcome

Then, in our routes we can display it like this:

Route::get('/demo', function () {
    return new App\Mail\UserWelcome();
});

Finally, here is the browser view of this email:

Outside of testing the email through the browser, another use case for this feature is to easily create web views of all the emails you send for when the message is all garbled when it arrives.

This new Render feature will be available with Laravel 5.5 that is due out in July or August. Be sure and join the newsletter to not miss out on the release announcement.


Filed in: Laravel 5.5 / Mailable


Newsletter

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

Laravel News Partners

Laravel Jobs

Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
Full Stack Software Engineer
Atlanta, GA or Remote
Voxie
Laravel/PHP Developer
Chicago, IL
Neon One
Software Engineer, Web Applications
Vaughan, ON, Canada
Blast Motion
Contract Services Software Engineer (Laravel | Vue | Tailwind)
Remote
Riverbed Technology
Senior Laravel Developer
Wilmington, NC
GE Software Inc.
Senior Full Stack Developer (PHP | Vue | DDD)
Charleston, SC
MassageBook