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.
No comments:
Post a Comment