Skip to content

Laravel – Quickly Send or Test Emails while on localhost using Mailhog and Tinker

A common problem or question while developing Laravel websites on localhost using MAMP or similar tools is you cant get to send or test email related functionality.

Well there is a very easy and smooth option to enable sending emails and even you can check it right in your browser. To summarise, we will be using Mailhog (to send/receive emails) and Laravel’s Tinker to test sending email from localhost. Below is the step by step guide on how you can do it:

First and Foremost

Installing Mailhog:

brew install mailhog

If brew command doesn’t work for you, I recommend installing Homebrew package manager for MacOS, will make your lives a lot easier.

Starting Mailhog Server

brew services start mailhog

Starts the Mailhog server in background. (if you just want to run it temporarily just type the command “mailhog” and you will see the mailhog running prompts)

All right yo..! You have a Mail server running on your mac now. Check your mails on the link below:

http://0.0.0.0:8025/

Setting up the Laravel env

Add below smtp settings in your env file:


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

Lets test it out:

Open up Laravel Tinker in your Terminal: php artisan tinker

Send an email using the below command:

Mail::send('errors.503', [], function ($message) { $message->to('abcd@xyz.com')->subject('this works!'); });

Check the Mailhog browser (Default: http://0.0.0.0:8025/) and you should have got an email from your laravel setup (not a fancy template though, but it works).

Hope this helps.

Until next time. Cheers.

2 thoughts on “Laravel – Quickly Send or Test Emails while on localhost using Mailhog and Tinker”

  1. Facade/Ignition/Exceptions/ViewException with message ‘PHP Notice: Undefined variable: exception in /Users/admin/Sites/members/storage/framework/views/9f740c96302226d4b85eb3fbd7ee9e20c061bb81.php on line 3 (View: /Users/admin/Sites/members/resources/views/errors/503.blade.php)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.