Home / Snippets / How to Preview Laravel Mail On Browser During Development
How to Preview Laravel Mail On Browser During Development cover

How to Preview Laravel Mail On Browser During Development

866

3 years ago

0 comments

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.
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this