Copied!
Laravel

Setup Mailpit for Laravel: The Best Free Local Email Testing Tool

setup-mailpit-for-laravel
Shahroz Javed
Oct 22, 2025 . 19 views

Table Of Contents

 

Introduction

When developing a Laravel project, testing email functionality locally can be tricky — especially when you don't want to send real emails during development. That’s where Mailpit comes in. It’s a lightweight, fast, and modern local SMTP testing tool that captures outgoing emails and displays them beautifully in a web interface.

💡 Related: You may also like our post on How to Send Emails in Laravel with Mailables.

Why Use Mailpit for Laravel Email Testing?

Mailpit allows you to test, preview, and debug emails from your Laravel app without actually sending them. It acts as a fake SMTP server, catching all outgoing messages for local inspection. Perfect for developers who need to verify templates, email content, and configurations.

Download and Run Mailpit

Mailpit is a single executable file — no installation required. You just download and run it. Follow these steps:

# Step 1: Download Mailpit for Windows
https://github.com/axllent/mailpit/releases

# Step 2: Open CMD in the folder where mailpit.exe exists
cd path\to\mailpit\folder

# Step 3: Run Mailpit
mailpit.exe

Once Mailpit is running, open your browser and visit:

http://localhost:8025/

You’ll now see the Mailpit dashboard, ready to capture emails sent from your Laravel app.

Mailpit's clean and responsive email viewer interface

Configure Laravel to Use Mailpit

Now that Mailpit is running locally, update your .env file to send all emails through it:

MAIL_MAILER=smtp
MAIL_HOST=127.0.0.1
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="test@example.com"
MAIL_FROM_NAME="${APP_NAME}"

This configuration tells Laravel to send all emails through the local Mailpit SMTP server instead of external ones like Gmail or Mailgun.

⚠️ Note: Make sure Mailpit is running before sending test emails; otherwise, Laravel will throw a connection error.

Optimize Laravel Cache (Optional)

After updating your .env file, clear and rebuild Laravel’s configuration cache:

php artisan optimize

Send Test Email from Tinker

To confirm your Mailpit setup works, send a test email using Laravel Tinker:

php artisan tinker

> Mail::raw('Hello from Mailpit', function($m) {
>     $m->to('someone@example.com');
>     $m->subject('Mailpit Test');
> });

If everything is configured correctly, open http://localhost:8025/ — you’ll see your test email instantly.

Result

Once you refresh Mailpit’s web interface, you’ll see your captured email with subject, body, headers, and even HTML preview. This makes it super easy to validate email designs and content before deploying your Laravel project.

Laravel test email captured in Mailpit

Conclusion

Using Mailpit with Laravel is one of the simplest ways to test email functionality locally. It’s fast, lightweight, and doesn’t require any configuration beyond your .env file. Whether you’re debugging a notification, testing templates, or verifying a password reset email — Mailpit makes it seamless.