I ran into a MailHog Docker networking issue while testing a WordPress Core ticket, I needed to verify email functionality in my local development environment using MailHog. I am using the wordpress-develop
Docker setup, so I assumed setting up MailHog would be simple.
To test it, I first installed the Check & Log Email plugin. I tried sending a test email, and it failed but without giving much detail. All I could see was an error as shown in the screenshot below.

That wasn’t enough to debug and that is what AI tool suggested. So I switched to WP Mail SMTP, which provided detailed SMTP error logs.
Versions:
WordPress: 6.9-alpha-60093-src
WordPress MS: No
PHP: 8.2.15
WP Mail SMTP: 4.5.0
Params:
Mailer: smtp
Constants: No
ErrorInfo: SMTP Error: Could not connect to SMTP host. Failed to connect to serverSMTP server error: Failed to connect to server Additional SMTP info: php_network_getaddresses: getaddrinfo for mailhog failed: Name or service not known
Host: mailhog
Port: 1025
SMTPSecure: string(0) ""
SMTPAutoTLS: bool(false)
SMTPAuth: bool(false)
Server:
OpenSSL: OpenSSL 1.1.1w 11 Sep 2023
Debug:
Email Source: WP Mail SMTP
Mailer: Other SMTP
SMTP Error: Could not connect to SMTP host. Failed to connect to serverSMTP server error: Failed to connect to server Additional SMTP info: php_network_getaddresses: getaddrinfo for mailhog failed: Name or service not known
SMTP Debug:
2025-06-30 17:37:41 Connection: opening to mailhog:1025, timeout=30, options=array()
2025-06-30 17:37:41 Connection failed. Error #2: stream_socket_client(): php_network_getaddresses: getaddrinfo for mailhog failed: Name or service not known [/var/www/src/wp-includes/PHPMailer/SMTP.php line 412]
2025-06-30 17:37:41 Connection failed. Error #2: stream_socket_client(): Unable to connect to mailhog:1025 (php_network_getaddresses: getaddrinfo for mailhog failed: Name or service not known) [/var/www/src/wp-includes/PHPMailer/SMTP.php line 412]
2025-06-30 17:37:41 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo for mailhog failed: Name or service not known (0)
SMTP Error: Could not connect to SMTP host. Failed to connect to server
So here we have more information to debug the issue. But before we dive into the debugging I want to make sure to mention the real part: I wouldn’t have figured this out on my own. With the help of AI (yes, ChatGPT!), I walked through debugging, inspected Docker networks, tweaked docker-compose.override.yml
, and eventually got everything working.
This post is for anyone who’s:
- Running WordPress in Docker
- Using MailHog to test email
- And getting nowhere with vague connection errors
Let’s walk through what went wrong and how I was able to fix it with AI tools.
The Setup: WP + MailHog + Docker + WP Mail SMTP
I had the following setup:
- WordPress running via Docker Compose
- MailHog container exposed on port
1025
- Email testing plugins:
- Check & Log Email (used first, limited insight)
- WP Mail SMTP (used next, provided full debug output)
- SMTP settings:
- Host:
mailhog
- Port:
1025
- Encryption:
None
- Auth: Off
- Host:
The Error Part
The key error I got from WP Mail SMTP was:
SMTP Error: Could not connect to SMTP host. php_network_getaddresses: getaddrinfo for mailhog failed: Name or service not known
And once I also facd the below error:
STARTTLS command failed: 500 Unrecognised command
That means:
- MailHog was unreachable from the container
- Or MailHog didn’t support TLS
The Real Issue: Docker Network Mismatch
After a detailed debugging it was found out that:
- My PHP/WordPress container was on the
wordpress-develop_wpdevnet
network - My MailHog container was on the default
bridge
network
So when WordPress tried to send mail using mailhog:1025
, it failed because DNS resolution doesn’t work across isolated Docker networks.
The Fix: Make the Containers Talk
To fix this, it was mandatory to make sure both containers shared the same Docker network.
Step 1: Create a Shared Docker Network
docker network create wpdevnet
If this already exists (as part of wordpress-develop
), you’ll see a message and can move on.
Step 2: Update docker-compose.override.yml
Add this file (or update if it exists) in your root project directory. But the safest option is to create the new one.
services:
mailhog:
image: mailhog/mailhog
ports:
- "8025:8025" # MailHog Web UI
- "1025:1025" # SMTP
networks:
- wpdevnet
networks:
wpdevnet:
external: true
name: wpdevnet
This tells Docker to run the mailhog
container on the same custom network used by the main WordPress containers.
Step 3: Restart Everything
docker compose down --volumes
docker compose up -d
Step 4: Configure WP Mail SMTP and Save the changes
Inside WordPress:
- Mailer: Other SMTP
- SMTP Host: mailhog
- Port: 1025
- Encryption: None
- Auto TLS: Off
- Authentication: Off
Do NOT use TLS — MailHog doesn’t support encryption.
If you do, you’ll get this error:
STARTTLS command failed: 500 Unrecognised command
Success: Emails Now Appear in MailHog
Test emails from WordPress showed up in the MailHog UI at http://localhost:8025
WP Mail SMTP logs showed clean delivery. No more guessing; just working local email testing 🎉
What I Learned (and Why It Matters)
- Docker containers can only resolve hostnames if they’re on the same network ✅
- MailHog is a brilliant tool but lacks TLS, so you need to configure accordingly
- Sometimes the problem is not in code, but your environment setup
- And yes — AI can be your debugging buddy
Using ChatGPT helped me understand not just what to change, but why it mattered. It didn’t give me a copy-paste answer rather it gave me confidence to keep digging in.
Without AI guiding me through logs, Docker commands, and debug paths, I might have spent hours stuck. Instead, I walked away with a new Docker concept understanding, a fix that works, and a blog post I’m proud to share. ✨
Leave a Reply