Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Email delivery

PHPMailer cannot connect to the SMTP host from a GoDaddy server

ErrorSMTP Error: Could not connect to SMTP host.

Short answer

PHPMailer reports Could not connect to SMTP host when the TCP connection to the mail server fails. On GoDaddy hosting the usual reason is that outbound SMTP on ports 25, 465 and 587 is blocked except to GoDaddy's own relay. Turn on debug output to confirm, then send through the local relay as GoDaddy documents it.

  • Applies to PHPMailer 6.9, PHP 8.3, cPanel hosting
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Turn the debug level up to connection details and read the first lines. They show which host and port PHPMailer tried and how it failed.

    $mail->SMTPDebug = SMTP::DEBUG_CONNECTION;
    $mail->Debugoutput = 'error_log';
  2. 2Match what you see, then jump to its fix

    1. 1Timeouts or refusals to smtp.gmail.com, your mail provider or any external host, on ports 25, 465 and 587 alikeThe hosting provider blocks outbound SMTPFix
    2. 2The failure is the same whatever message you send, and the debug output ends at the connection stepPort 25 is filtered, or the wrong host or port is setFix

What does the error look like?

  • SMTP Error: Could not connect to SMTP host.
  • SMTP connect() failed.
  • Connection refused

Cause 1 of 2

The hosting provider blocks outbound SMTP

1Check

The PHPMailer troubleshooting guide states that GoDaddy blocks outbound SMTP on those ports to all servers except its own. Test the same host from your own computer: if it works there, the block is on the server side.

$mail->Host = 'smtp.example.com';
$mail->Port = 587;
$mail->SMTPDebug = SMTP::DEBUG_CONNECTION;

2Fix

Send through the server's local relay, as the guide describes: host localhost, port 25, no authentication and no automatic TLS.

$mail->isSMTP();
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->SMTPAuth = false;
$mail->SMTPAutoTLS = false;

3Verify

Send one test message and read the debug output; the connection step should succeed.

php send-test.php

Confirmed by github.com

Did this fix it?

Cause 2 of 2

Port 25 is filtered, or the wrong host or port is set

1Check

The guide notes that port 25 is the one most often diverted or blocked and often has no encryption, so ports 465 and 587 are preferred. If a port check fails, the server is down or the host or port is wrong.

grep -n -E 'Host|Port|SMTPSecure' send-mail.php

2Fix

Use the host and port your mail provider documents, with 587 (STARTTLS) or 465 (SMTPS), when the hosting plan allows outbound SMTP. If it does not, ask the hosting provider to unblock it.

$mail->Host = 'smtp.example.com';
$mail->Port = 587;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;

3Verify

Send a test message and confirm the debug output moves past the connection step.

php send-test.php

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Keep SMTPDebug at 0 in production and enable it only for a test run.
  • Read the hosting plan's rules for outbound mail before choosing an SMTP provider.
  • Send one test message after every hosting or DNS change.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Email

PHP mail() returns true but the email never arrives

Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing

mail() returning true only means the message was accepted for delivery, not that it arrived.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.