SMTP connection refused: what ECONNREFUSED means and how to fix it
Connection refused means a host answered but nothing listens on that port: wrong port, wrong host (localhost with no MTA), a service down, or a firewall that rejects instead of drops. Fixes for WordPress "Connection refused", Nodemailer ECONNREFUSED and PHPMailer "SMTP connect() failed".
What ECONNREFUSED means: The TCP connection was actively rejected (RST). Unlike a timeout, the network path works — the target simply is not listening on that port, or a firewall replies "no".
Causes, most likely first — and the fix for each
- Host left as localhost/127.0.0.1 (WordPress and Laravel defaults) with no mail server installed on the web server.
Fix: Set the real SMTP host (e.g. smtp.queensmtp.com) and port 587/465 with authentication. - Wrong port for the provider (e.g. 465 on a server that only offers 587, or 25 on a submission-only host).
Fix: Use the port from the provider's settings page. - A host firewall (customer's hosting provider) rejects outbound SMTP to third parties — common on some shared hosts that force their own relay.
Fix: Ask the host to allow outbound 587/465, use 2525, or use the relay's HTTPS API instead of SMTP. - The mail server is down or restarting (your own Postfix/Exim).
Fix: systemctl status postfix; check it listens with ss -ltnp. - Docker: the app container connects to "localhost" expecting the host's MTA.
Fix: Use the service name or host.docker.internal, or point the container directly at the external relay.
How to confirm which one you have
nc -vz host port from the same machine/container: "refused" confirms nothing listens there; try the provider's other ports.
Open the SMTP tester Check SPF / DKIM / DMARC
Still stuck? Use a relay that tells you why
QueenSMTP shows every message's exact server reply in the log, verifies your domain's SPF and DKIM before you send, and is not subject to mailbox-provider caps. $5/year plus $0.10 per 1,000 emails; 100 a day free to test.
Try it freeRelated errors
Questions about ECONNREFUSED
Almost never. Either the host/port are wrong, or the hosting provider's firewall blocks outbound SMTP. Test with port 2525, and if that is refused too, ask the host or switch to an API-based sending option.
Related Guides
Continue learning with these related articles