Posts Learn Components Snippets Categories Tags Tools About

How to Preview Laravel Mail On Browser During Development

Learn how to preview your Laravel mail design during development from your browser using Laravel Mailable

Created on Aug 05, 2021


Designing a mail template is quite a challenge on normal web applications, but in the case of Laravel, you can make use Laravel Mailable template and preview the rendered mailable in the browser just like any of the typical Laravel Blade templates.

Return Mailable Instance
You can return a mailable instance from any of your controller files or directly from the route body like below.
Route::get('/welcome-user-mailable', function () {
    $user = App\Models\User::find(1);

    return new App\Mail\WelcomeUser($user);

By doing so you can focus on designing how the mail should look from the browser and when it's ready then send it to an actual email address.

Do note that inline attachments won't be rendered when previewing in the browser so you will have to use Mailhog or any of the related services.

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️