Blog Details
SHAHRIAR RAHAT
29 Oct 2024
6 min read
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.
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.
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:
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
After downloading, open your Downloads folder, locate mailpit-windows-amd64.zip
, and extract its contents:
mailpit-windows-amd64.zip
.mailpit-windows-amd64
folder from your Downloads folder.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.
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.
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.
In your project’s email configuration, set Mailpit as the local SMTP server:
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.
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
.
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"
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.
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."
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.
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.
Don’t worry, we don’t spam!