How to render emails in browser using Laravel

Customizing a Mail template can be time-consuming, especially when you have to send a test emaildummy mail to yourself to know how it looks. It is important that you are satisfied with how the end result looks.

How to render emails

The best way to render your mail on your browser is to keep refreshing the browser as you change the template. This method is effortless and straightforward.


This should only be done while testing.

Working

Run this command:


php artisan make:mail UserRegisteredMail –markdown emails.user-email

This creates two things:

  • An email directory in the app directory which contains: UserRegisteredMail.php

  • An email directory in the view directory which contains: user-email.blade.php

In order to render it in your browser, you have to create a route. Let’s try a /email route with a get method such as this:


Route::get(‘/email’, function(){
return new UserRegisteredMail();
});

Summary

Rendering a mail in the browser is time-saving and it allows you to know what your end-users receive when an email has been sent to them.

Free Resources