If you are trying to send an email using an SMTP provider like Amazon SES, SendGrid, Mailgun, etc. and you are getting a “Connection refused (111)” error then it means that your server has blocked sending emails through port 25, 465, or 587.


Sending an email using PHPMailer and Amazon SES generates an error message;

SMTP ERROR: Failed to connect to server: Connection refused (111)<br> SMTP connect() failed.”

The error above means that your hosting provider or server is restricting outgoing emails sent via a third-party SMTP service provider.

Solution 1:  Disable Blocked SMTP Ports

a) The first solution is to open the script that you are using to process email sending and change $mail->IsSMTP() to $mail->IsMail().

b) The other solution is to Login to your WHM/cPanel account and then search “Tweak Settings“. In Tweak Settings go to email, then under “restrict outgoing SMTP to root, exim and mailaman” turn off the option. If it is already off and not working then try another option below.

c) While in WHM, Search for “ConfigServer Security & Firewall” and go to Firewall Configuration. Under SMTP settings Turn off SMTP Blockand remove the SMTP port number you are using from the block list.

If the above solutions do not work, then contact your host to find out whether they have blocked outgoing SMTP emails at the server level.

Solution 2:  Sending Emails with API

d) If email sending via scripts like PHMailer is permanently blocked, then the other option is to use SMTP email API. The best option is Amazon SES API using the AWS SDK for PHP. This option works even if the SMTP ports are blocked.

Let us know what worked for you in the comments below.