Preview email sent from Laravel

Original author: Mohamed Said
  • Transfer
As Said wrote on his Twitter channel:


“My new package for @laravelphp converts the letters you send into .html for validation at the development stage.”

This package introduces a new driver for previewing mail in Laravel. If necessary, it will output sent e-mail messages, saving it as an HTML document, allowing you to check its appearance.

image


Installation


To install the package, run the command using Composer:

composer require themsaid/laravel-mail-preview


After Composer finishes adding the package, add the service provider to the appropriate section of the file `config / app.php`:

'providers' => [
//...
    Themsaid\MailPreview\MailPreviewServiceProvider::class
];


And finally publish the configuration file:

php artisan vendor:publish


The only thing you need to do - is to change the value of the variable MAIL_DRIVER file `.env` on` preview `

How it works


When sending each email, it will be converted into an HTML-format file, saved in the ' storage / email-previews ' folder with the name of the file containing the recipient's email address and header:

1457904864_jack_at_gmail_com_invoice_000234.html


When you open the file in a web browser, you can see how the letter you sent will look like. Please note that there may be some visual differences in the letter when users view messages in a particular mail client.

At the beginning of the generated file you will find an HTML comment with all the details of the message:



Package configuration


In the configuration file, you can change the path to save the generated files, as well as the maximum lifetime for such files. After the lifetime has expired, the generated files will be deleted.

Note from the translator


In my opinion, this is a really necessary package for the developer, since quite often you have to send test emails to yourself to verify the correctness of its display. The package developed by Said really simplifies the task of composing email messages.

UPD: repository is here

Also popular now: