Datadog collects and monitors your PHP app metrics and distributed traces in real-time with application performance monitoring. Decrease downtime and performance issues with Datadog APM by tracing requests across service boundaries and drilling into individual traces end-to-end with flame graphs. Start your 14-day trial for free today.

A mail driver to quickly preview mail in Laravel apps

Original – by Freek Van der Herten – 3 minute read

Using our laravel-mail-preview package, you can quickly display mails that are sent by your Laravel application in your browser.

Today, we've released v5 of the package. In this blog post, I'd like to tell you all about it.

A bit of history

This package was not originally created by our team, but by Mohamed Said. Ever since Mohamed released it, we've been using it in several of our projects. Because we wanted to modernize the package, and Mohamed didn't have time to do this, Mohamed graciously decided to hand over the package to us. We'd like to thank Mohamed for entrusting his work to us.

If you were already using themsaid/laravel-mail-preview v4, then the only thing you need to do is change that in your composer.json to spatie/laravel-mail-preview v4. The API is identical; nothing has changed in the v4 version.

Introducing laravel-mail-preview

A new major release of spatie/laravel-mail-preview, v5, was released today. This version is a rewrite v4 using the latest and greatest Laravel features.

The core functionality has remained the same. Whenever a mail is sent in your application, the package will inject a small overlay with a link to that sent mail. This is what that overlay looks like.

overlay

This allows you to test out the mail in your browser quickly. This is pretty handy when using the site locally. For example, when you want to change your password, you can simply submit the forgot password form. The link to the mail will be displayed in your browser. When you click it, you see the mail's content, and you can click the reset password link. So, you can use the entire e-mail flow without leaving your browser.

This package is also convenient in Dusk tests. Using the same scenario as above, you can quickly write a Dusk test to test that reset password flow. You just have to click links using the automated browser in your test.

We've made sure that the package is extensible, you can publish the views to customize that overlay and how the content of a mail is displayed. When a mail is stored, an event is fired, so you can listen for that to perform custom logic.

Additionally, the package will also store any sent mails in the storage directory of your app. Two versions will be stored. The HTML version can be displayed in the browser, the eml version can be opened in any modern e-mail client. This allows you to see how the mail looks like in your particular e-mail client.

In closing

Right now, the package only has the feature set that Mohamed initially coded up. We've got some features in mind that we'll add to the package soon to make it even easier to test your e-mails. Keep an eye out on the repo.

Be sure, to also take a look at this list of packages that our team has created previously.

Thanks again Mohamed for entrusting us with your great package. We'll take good care of it!

Stay up to date with all things Laravel, PHP, and JavaScript.

Follow me on Twitter. I regularly tweet out programming tips, and what I myself have learned in ongoing projects.

Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

Comments

Webmentions

Christopher liked on 30th January 2021
Codingcafe liked on 30th January 2021
MarcoDM liked on 30th January 2021
Sanjeeva liked on 29th January 2021
Sanjeeva retweeted on 29th January 2021
Diar liked on 29th January 2021
Eldar Gadirov liked on 29th January 2021
8000plus, d.o.o. liked on 29th January 2021
Ashish Srivastava liked on 29th January 2021
Helder Neves liked on 29th January 2021
Stephen Shead liked on 29th January 2021
Ihor Vorotnov liked on 29th January 2021
Haneef Ansari 🍭 liked on 29th January 2021
Vaibhav Pardeshi liked on 29th January 2021
Ibnu Halim Mustofa liked on 29th January 2021
eshanit bro retweeted on 29th January 2021
Zach Williams liked on 29th January 2021
newwave liked on 29th January 2021
eshanit bro liked on 29th January 2021
Godwin liked on 29th January 2021
Dumitru Botezatu liked on 29th January 2021
Peter Brinck 🤘 liked on 28th January 2021
-nees- liked on 28th January 2021
Tauseef shah liked on 28th January 2021
Apideck liked on 28th January 2021
Mo Khosh liked on 28th January 2021
Jurre Vriezinga liked on 28th January 2021
Simon Blonér liked on 28th January 2021
Tall Stack retweeted on 28th January 2021
Tall Stack liked on 28th January 2021
PHP Synopsis retweeted on 28th January 2021
Derick Alangi ⚜️ liked on 28th January 2021
Fred C. liked on 28th January 2021
Flamur Mavraj liked on 28th January 2021
Edwin I Arellano liked on 28th January 2021
trevor retweeted on 28th January 2021
trevor liked on 28th January 2021
Huan liked on 28th January 2021
Matt Murtaugh liked on 28th January 2021
George liked on 28th January 2021
De Saint Florent liked on 28th January 2021
Luís Dalmolin liked on 28th January 2021
Klemen Magajne liked on 28th January 2021
Nii Adjetey Sowah liked on 28th January 2021
Michael Leigeber liked on 28th January 2021
Rando Hinn liked on 28th January 2021
amr liked on 28th January 2021
Yusuf Onur SARI liked on 28th January 2021
satriyo pamungkas liked on 28th January 2021
Rias Van der Veken liked on 28th January 2021
ndifón liked on 28th January 2021
Adrien Beaudouin liked on 28th January 2021
Jamie York liked on 28th January 2021
Sam Carré 🤠 liked on 28th January 2021
🧔🏻Victor Yoalli liked on 28th January 2021
Richard Radermacher liked on 28th January 2021
José Cage liked on 28th January 2021
Omar Andrés Barbosa Ortiz liked on 28th January 2021
onatcer liked on 28th January 2021
Robin Dirksen liked on 28th January 2021