Local Mail Server for Testing Emails Instead of Using MailTrap.io – A Guide for Laragon Users
Learn the essential skills and steps to become a full stack developer. Start your journey today with this comprehensive guide for beginners!
Last Update: 29 Oct 2024

Introduction
Setting up a local environment for web development often requires tools to simulate various services, such as sending emails. Laragon, a powerful local development environment for Windows, comes packed with features that make it a favorite among PHP and Laravel developers. One of Laragon’s lesser-known but useful functionalities is its built-in Mail Catcher, which captures emails sent through PHP's mail() function. However, for those seeking a more versatile local mailbox setup, Mailpit is an excellent alternative, keeping emails within the local system for testing without them leaving the PC.
Here’s a step-by-step guide to installing and configuring Mailpit with Laragon, making local email testing smoother and more secure.
Why Use Laragon?
Laragon is a comprehensive environment manager that stands out due to its portability, efficiency, and flexibility, making it a top choice among Laravel and PHP developers. It offers robust features like an isolated environment, a quick setup process, and powerful tools such as Node.js, PHP, MySQL, and Nginx, all within an easy-to-navigate interface. With Laragon, you can emulate production settings locally and experiment with multiple PHP versions, making development fast and seamless.
Setting Up Mailpit with Laragon
With Mailpit, emails sent from your applications stay on your local machine, allowing you to test without affecting real users.
Follow these steps to integrate Mailpit into your Laragon environment:
1. Download Mailpit
Visit the Mailpit GitHub repository and download the latest release for Windows. Look for the mailpit-windows-amd64.zip
file in the releases section. Go here - https://github.com/axllent/mailpit/releases/tag/v1.21.0
2. Extract the Zip File
After downloading, open your Downloads folder, locate mailpit-windows-amd64.zip
, and extract its contents:
- Right-click on
mailpit-windows-amd64.zip
. - Select “Extract All…” and complete the extraction process.
- Copy the
mailpit-windows-amd64
folder from your Downloads folder.
3. Move Mailpit to Laragon
Go to your Laragon installation directory and navigate to the bin
folder. Paste the extracted Mailpit directory here and rename it to mailpit
for easier access.
4. Modify the Hosts File
In Laragon, open the hosts file to set up Mailpit’s local domain:
-
Click on the red "H" icon in Laragon (you may need to grant administrator permissions).
-
This opens
C:\WINDOWS\system32\drivers\etc\hosts
in Notepad++ by default. -
Add the following line before any Laragon magic comments:
Manual 127.0.0.1 mailpit # Manual for laragon\bin\mailpit\mailpit.exe
-
Save the file and allow elevated privileges if prompted.
5. Configure Autostart
To start Mailpit automatically with Laragon, modify Laragon’s Procfile:
-
Go to
Laragon menu > Laragon > Procfile
. -
Add the following lines:
Mailpit.exe : autorun mailpit.exe PWD=C:\laragon\bin\mailpit Mailpit Admin : autorun http://mailpit:8025
Each time you start Laragon, Mailpit will launch automatically in the background, and the Mailpit admin interface will open in your browser.
Setting Up Project Email Settings
In your project’s email configuration, set Mailpit as the local SMTP server:
- Protocol: SMTP
- Hostname: mailpit
- Port: 1025
For Laravel applications (default Laravel 10+ settings), add these entries in the .env
file:
MAIL_MAILER=smtp MAIL_HOST=mailpit MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null
No further configuration is required—your Laravel app is now ready for testing with Mailpit.
Testing the Setup
To test if Mailpit is working correctly:
-
Start Laragon (or restart it if it’s already running). The Mailpit admin page should open automatically.
-
In any Laravel project, open a Tinker console by running
php artisan tinker
. -
Send a test email:
Mail::send('welcome', [], fn($message) => $message->to('admin@example.com')->subject('Testing Mailpit'));
If everything is set up correctly, you should see a confirmation message in Tinker, and the email should appear in the Mailpit admin interface at http://mailpit:8025
.
Configuring PHP mail() Function
To capture emails sent using PHP's mail() function, update the php.ini
settings in Laragon:
-
Go to
Laragon menu > PHP > php.ini
. -
Locate the
[mail function]
section and configure as follows:[mail function] SMTP = mailpit smtp_port = 1025 sendmail_from = laragon@example.com sendmail_path = "C:/laragon/bin/mailpit/mailpit.exe sendmail"
Testing PHP’s mail() Function
To verify PHP mail() is configured properly:
-
Open the terminal and enter the PHP interactive shell:
-
Type the following command:
mail('my_mail@example.com', 'Test', 'Test message', 'From: Laragon');
-
Check the Mailpit interface at
http://mailpit:8025
to view the message.
Stopping Mailpit
Mailpit starts automatically with Laragon but does not shut down when Laragon is closed. To stop Mailpit:
-
Open the command line and type:
-
To terminate the process, use:
Alternatively, you can stop it via Task Manager by locating mailpit.exe
in the background processes list, right-clicking, and selecting "End Task."
Troubleshooting
If you encounter the error:
ensure Mailpit is running. You can start it manually by double-clicking the mailpit.exe
file or using the Laragon menu to launch Mailpit.
Final Thoughts
Mailpit is an excellent local mail solution for testing emails in Laragon without sending them externally. Its lightweight, reliable setup and easy integration with Laragon make it a preferred tool for developers needing a secure, local email testing environment.
Trendingblogs
Get the best of our content straight to your inbox!
By submitting, you agree to our privacy policy.