Setup MailHog with Laravel Valet

As you might know, Laravel Valet makes it super easy to do development on your Mac. For Laravel there are some great packages to handle mail testing such as MailThief and Laravel Mail Preview Driver. You could also use a online service like Mailtrap to do mail testing. Another option I want to discuss is MailHog which is a local email testing tool for developers. By using it, you can view the mails that your app sent in the browser! I never heard about it until it got included in Laravel Homestead recently but it's actually quite easy to setup if you're using Laravel Valet as well!

First we have to install MailHog on your Mac. With brew, which is also used to setup Laravel Valet, this is a breeze. Brew can also start MailHog as a service.

brew install mailhog
brew services start mailhog

With any luck it's now possible to open MailHog's UI in the browser by visiting http://127.0.0.1:8025. Finally you have to edit your app's mail config. You can do it directly in the mail.php config file, but I like to keep these settings in the .env file:

MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

That's it! Now when your app sends a mail, it will be send to the local MailHog service so you can view it the browser. It even has support for notifications!