📜 ⬆️ ⬇️

Preview of email sent from Laravel

As Said wrote on his Twitter channel:


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

This package introduces a new driver for previewing mail in Laravel. If necessary, it will output the sent emails, saving it as an HTML document, allowing you to check its appearance.
')
image


Installation


To install a package, execute the command using Composer:

composer require themsaid/laravel-mail-preview 


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

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


And finally publish the configuration file:

 php artisan vendor:publish 


The only thing you need to do is change the value of the variable MAIL_DRIVER in the file `. Env` to` preview `

How it works


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

 1457904864_jack_at_gmail_com_invoice_000234.html 


When you open the file in a web browser, you can see how the email you sent will look like. It should be noted that some visual differences of the letter are possible when users view a message 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:

 <!-- From:{"info@acme.com":"Acme HQ"}, to:{"jack@gmail.com":"Jack Black"}, reply-to:"info@acme.com", cc:[{"finance@acme.com":"Acme Finance"}, {"management@acme.com":"Acme Management"}], bcc:null, subject:Invoice #000234 --> 


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 expiration date, the generated files will be deleted.

Note from the translator


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

UPD: repository is here

Source: https://habr.com/ru/post/279171/


All Articles