Learn how to use MailHog in Magento 2 with Docker. Follow this simple setup to test outgoing emails directly from your container. Our Live Support Team is always here to help you.
Set Up MailHog in Magento 2 with Docker
When you’re developing on Magento 2 with Docker, one of the most common issues is not seeing outgoing emails during testing. That’s where MailHog steps in, it catches all your application emails, so you can see exactly what’s being sent without touching a real inbox.
In this guide, we’ll walk through how to use MailHog in Magento 2 development with Docker. It’s fast, simple, and makes debugging email issues much easier. Let’s get right to it.

Overview
Why MailHog Matters for Magento 2 Developers
Every Magento 2 developer has hit that point, you trigger a password reset or order email, and nothing shows up. Instead of guessing, you can use MailHog to view every outgoing email instantly from a web interface. No SMTP configurations, no production worries. Now, let’s see how to connect MailHog with your Magento 2 Docker environment.
How To Connect
1. Install MailHog Sendmail Tool in Your PHP Docker Container
The first thing you’ll need is the MailHog sendmail tool inside your PHP container. Use the following commands:
wget https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64
sudo chmod +x mhsendmail_linux_amd64
sudo mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail
These commands download and set up mhsendmail so PHP can route all emails through MailHog.
2. Update Your PHP Configuration
Next, edit your php.ini file and update the sendmail_path value. This ensures all outgoing mail from PHP uses MailHog instead of a real SMTP server.
sendmail_path = '/usr/local/bin/mhsendmail --smtp-addr="mailhog-cont:1025"'
This small tweak redirects every mail function in PHP directly to your MailHog container.
3. Add MailHog to Your Docker Compose File
Now, it’s time to include MailHog in your Docker setup. Open your docker-compose.yml and add the following service:
mailhog-cont:
container_name: pvh-mailhog
image: mailhog/mailhog
networks:
magento23_app_net:
ipv4_address: 10.0.0.25
This creates a dedicated MailHog container connected to your Magento 2 Docker network. Once it’s running, MailHog will start capturing all your outgoing emails automatically.
Catch Every Email Instantly Today!

4. Restart PHP-FPM and Test
After adding MailHog, restart PHP-FPM to apply the configuration.
sudo service php7.4-fpm restart
Then, test email sending from PHP directly:
php -r "$from = $to = 'bob.cares@gmail.com'; $x = mail($to, 'testing from php cli', 'Hello World', 'From: '. $from); var_dump($x);"
If everything’s set up correctly, MailHog will capture this test message instantly.
5. View Emails in MailHog
Once your test runs, you can check the results either through the API or the MailHog web interface.
curl http://10.0.0.25:8025/api/v2/messages
http://10.0.0.25:8025
Open the web URL in your browser, and you’ll see every email your Magento 2 application has sent, subject lines, message bodies, and headers, all in one place.
Conclusion
Using this saves hours of frustration when debugging email issues. It gives you visibility into every outgoing message, lets you confirm templates, and avoids spamming real users during testing. Once you’ve tried this setup, you’ll never go back to guessing where your Magento 2 emails went again. Simple, quick, and effective, that’s the power of Magento 2 Docker MailHog integration.
