PHPMailer cannot connect to the SMTP host from a GoDaddy server
SMTP 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.
Fix it fast
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';2Match what you see, then jump to its fix
- 1
Timeouts 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
The 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
- 1
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.phpConfirmed by github.com
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.php2Fix
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.phpConfirmed by github.com
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
CodeIgniter email does not send and shows no error message
$email->printDebugger() prints an empty result
CodeIgniter signals a failed email only by send() returning false, with no exception.
4 causes, each with a fixLaravel tries to send mail to mailpit:1025 instead of your real SMTP server
Symfony\Component\Mailer\Exception\TransportException
Laravel is still using the development mail host from the starter .env, mailpit on port 1025, which only exists inside Laravel Sail.
3 causes, each with a fixLaravel mail fails because an address does not comply with RFC 2822
Email "Jane Doe <jane@example.com>" does not comply with addr-spec of RFC 2822.
Symfony Mailer checks every address when the Address object is created.
3 causes, each with a fixLaravel says the email was sent, but nothing arrives
Mail::to($user)->send() returns normally
Mail::send returns without an error when the message was accepted by the configured mailer, not when it was delivered.
3 causes, each with a fixLaravel mail fails with 'Unable to connect with STARTTLS' and SSL operation failed with code 1
stream_socket_enable_crypto(): Peer certificate verification failed
The mail server offered STARTTLS, but PHP could not verify the certificate it presented.
3 causes, each with a fixPHP 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