How to Set Up MailHog with Laravel Herd for WordPress Development
If you’re developing WordPress sites locally with Laravel Herd, testing email functionality can be awkward. Emails sent from a local environment do not actually reach real inboxes, which makes it harder to test features such as password resets, contact forms, or notification emails.
This is where MailHog fits in neatly.
MailHog is a developer tool that captures outgoing emails from your local environment and displays them in a web interface. Instead of being delivered to real recipients, emails are intercepted and stored for inspection. Think of it as a safety net for development emails.
In this tutorial, you’ll learn how to install MailHog and configure Laravel Herd to use it automatically, without modifying WordPress core files or installing additional plugins. The result is a setup similar to what tools like MAMP Pro provide, but using Herd and free, open‑source components.
Prerequisites
Before you begin, make sure you have:
- Laravel Herd installed (the free version works fine)
- Homebrew installed on macOS
- Basic familiarity with the command line
- A WordPress site running under Herd (optional)
This guide assumes you’re working on macOS. The steps apply to both Herd Free and Herd Pro, although Herd Pro includes its own mail server. If you’re on Windows, you can use MailHog’s Windows binaries instead.
What is MailHog?
MailHog is an email testing tool designed for local development. It runs a fake SMTP server that captures outgoing emails rather than sending them to real addresses. This prevents accidental emails during development while still allowing you to verify that email functionality works correctly.
MailHog’s key features include:
- A web interface for viewing captured emails
- Support for multiple storage backends
- An API for automated testing
- SMTP authentication support
- Optional message release for integration testing
Installing MailHog
The easiest way to install MailHog on macOS is via Homebrew. Open a terminal and run:
brew install mailhogOnce installed, start MailHog as a background service:
brew services start mailhogRunning MailHog as a service ensures it starts automatically when your Mac boots. It runs silently in the background.
To confirm everything is working, open your browser and visit:
http://127.0.0.1:8025or
http://localhost:8025You should see MailHog’s web interface with an empty inbox.
Configuring Herd’s PHP to Use MailHog
For MailHog to capture emails from WordPress or any other site/app in your Herd installation, PHP needs to be configured to send mail through MailHog instead of attempting direct delivery. PHP still believes it is sending mail normally — MailHog simply intercepts it before anything leaves your local machine.
Finding your PHP configuration files
Laravel Herd maintains separate PHP configuration directories for each installed PHP version.
The quickest way to open the active configuration file is:
herd iniThis opens the php.ini file for the currently selected PHP version.
Alternatively, you can navigate to the configuration directory manually:
cd ~/Library/Application\ Support/Herd/config/php/Or if you are like me, just hit the Herd icon in the top bar and select “Open configuration files”. This will open the above folder in Finder. You’ll see folders named by PHP version, for example:
83for PHP 8.384for PHP 8.485for PHP 8.5
Editing php.ini
Open the php.ini file for the PHP version you’re using. Locate the sendmail_path directive, which is usually commented out:
;sendmail_path =
Replace it with the following line. If you do not have a directive like this, you can directly add this line.
sendmail_path = "/opt/homebrew/bin/mailhog sendmail [email protected]"A few important points:
- Remove the leading semicolon to enable the setting if it is present.
- Ensure the path to the MailHog binary is correct. The above path is the default installation directory for Homebrew on Apple Silicon Macs. You can find the path by entering
brew --prefixin Terminal. - The email address is a placeholder and can be anything you want.
Save the file and close your editor.
If you switch between PHP versions in Herd, repeat this change for each version’s php.ini file. This ensures MailHog continues to work regardless of which PHP version your WordPress site uses.
Restarting Herd services
After updating PHP configuration, restart Herd to apply the changes:
- Click the Herd icon in the macOS menu bar
- Select Stop all
- Wait a few seconds
- Select Start all
This reloads PHP with the updated configuration. If you prefer the command-line, run herd restart.
Testing email capture
Quick command-line test
A simple way to verify your setup is to send a test email directly from PHP:
php -r "mail('[email protected]', 'Test Subject', 'This is a test email from MailHog');"Open MailHog’s web interface at http://127.0.0.1:8025. The email should appear almost immediately.

Testing with WordPress
If you were thinking that you need to install a plugin for WordPress to get it to work with MailHog, then I’ll have to disappoint you.
To test a real WordPress email:
- Go to the WordPress login screen
- Click Lost your password?
- Enter a username or email address
- Submit the form
WordPress generates a password reset email, which MailHog captures. Because WordPress sends mail using the wp_mail()function under the hood, this setup captures all WordPress emails without requiring any plugin-specific configuration. You can inspect the subject, body, headers, and HTML output in the MailHog interface.
Viewing captured emails
MailHog’s web interface provides several useful tools:
- Inbox listing with sender, recipient, and subject
- Full email preview
- Toggle between plain text and HTML rendering
- Raw source and header inspection
- Options to delete individual messages or clear the inbox
The inbox updates in real time as emails are sent.
Troubleshooting common issues
MailHog not starting
If MailHog fails to start, check for port conflicts:
lsof -i :1025
lsof -i :8025If another service is using these ports, stop it or reconfigure MailHog to use different ports.
Emails not being captured
Confirm the active sendmail_path setting:
php -i | grep sendmail_pathMake sure you:
- Edited the correct
php.inifile - Removed the leading semicolon
- Restarted Herd after making changes
Web interface not loading
Check whether MailHog is running:
brew services list | grep mailhogIf it is not running, start it:
brew services start mailhogManaging MailHog
Stopping MailHog
brew services stop mailhogRestarting MailHog
brew services restart mailhogChecking service status
brew services listBest practices
- Clear the inbox regularly during development
- Test email functionality before deploying to production
- Inspect headers to catch spam-related issues early
- Verify HTML rendering using MailHog’s preview
- Document the setup for team members using the same environment
Conclusion
Setting up MailHog with Laravel Herd makes email testing a straightforward part of your WordPress development workflow. Because the configuration happens at the PHP level, all emails are captured regardless of how they are generated.
The setup takes only a few minutes but can save significant time debugging email issues later. With MailHog running in the background, you can confidently test email functionality locally without worrying about accidental deliveries.



