Mailpit is a local email testing tool, similar to MailHog or MailCatcher, used by developers to capture and inspect emails sent by an application during development. It provides a web-based interface where you can view, search, and debug email messages without actually sending them to a live email server.
It is a very useful and developer friendly tool but there is no adequate documentation on how to set it up in a Laravel app. That's what we'll do today.
Basic Setup
- Install Mailpit: You can install it via Homebrew on macOS.
brew install mailpit
If you are on Windows or Linux you can download the static binary. Read this guide for more information.
- Run Mailpit: Start the Mailpit server by running:
mailpit
Or set it up to run automatically by running:
brew services start mailpit
-
Access Mailpit Web Interface:
Open your browser and go to
http://localhost:8025
to view incoming emails in the Mailpit UI.
Laravel Setup
Go to you .env
file and input this setup
MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=your username @ your system name here
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
You can get your user and system name by running the following command
echo "$(whoami)@$(hostname)"
That's all! Now whenever an email is sent from your laravel app you would be able to view it in the browser.
Top comments (1)
Great guide on setting up Mailpit for local email testing! Local email testing tools like Mailpit make life so much easier for Laravel developers, providing an efficient way to view and debug emails during development without relying on live servers. For those looking to test their Laravel applications in a scalable, production-ready environment, platforms like Cloudways offer managed hosting solutions that streamline setup and email configurations for Laravel. It’s a convenient option for developers who need reliable email handling alongside performance-driven hosting. Thanks for covering the Mailpit setup so thoroughly—it’s incredibly helpful!