Drupal users sometimes get the SMTP error "could not connect to smtp host" while sending mails from the site.
This error can happen when there is a firewall issue or as a result of incorrect SMTP details.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to resolve related Drupal errors.
In this context, we shall look into methods to fix Drupal SMTP error "could not connect to smtp host".
We sometimes receive requests complaining that they are receiving the following error while sending emails from Drupal:
phpmailerException: SMTP Error: Could not connect to SMTP host
The Main reasons for this error includes:
1. Firewall restrictions.
2. Email settings at the provider end.
3. SMTP auth support settings.
One of the first step to follow when we see the "could not connect to smtp host" error in Drupal is to enable the SMTP debug available on the SMTP configuration page.
When we try to send mails with this option enabled, it gives us a more detailed story of why we can't send the message.
1. SMTP auth support settings
As discussed earlier, a common reason for the error is the wrong SMTP settings. We recently fixed this error where the issue was that the port settings were entered incorrectly.
So, it was clear that PHPMailer was unable to contact the SMTP server defined in the mail server settings.
Similarly, another customer reported that his emails did not work after configuring the SMTP module in Drupal.
Therefore, we checked the SMTP server settings in Drupal. Then, they found that the wrong SMTP server name setting caused the problem with emails.
So, we solved the issue by providing the correct SMTP server name and port settings in Drupal SMTP server settings.
2. Email settings at the provider end
At times, this error could be related to restrictions at the email provider end. Often, users find that GMail blocked them from sending mails.
In this case, try moving to a dedicated SMTP transaction email server.
Sometimes users receive errors while using 25 ports for connection.
Switching to 465 worked in such cases.
Often, users also require to enable "less secure apps" on the gmail/google apps account. Also, they have to set up the smtp relay in the google apps admin console from the Advanced Settings option.
3. Firewall restriction
Our Support Experts have noticed cases where the SMTP ports are blocked at the server firewall end. Thus we need to allow access for firewall or network to send mail for Linux, windows and mac.
Following command set permission for Linux to allow ports 465 and 587.
i. iptables -I OUTPUT -p tcp –dport 465 -j ACCEPT
ii. iptables -I OUTPUT -p tcp –dport 587 -j ACCEPT
This article covers methods to resolve Drupal SMTP error "could not connect to smtp host".
Basically, this error happens as a result of improper Drupal SMTP settings such as wrong SMTP server name, wrong port settings, and so on.
To resolve this SMTP error, follow the steps given below:
1. Login into myaccount.google.com.
2. Click on the link connected apps & sites.
3. Allow less secure apps" to "ON" (near the bottom of the page).
Also, you can try the following to fix this SMTP error,
1. System access configuration
Need to allow access for firewall or network to send mail for linux, windows and mac.
Following command set permission for linux.
i. iptables -I OUTPUT -p tcp --dport 465 -j ACCEPT
ii. iptables -I OUTPUT -p tcp --dport 587 -j ACCEPT
2. SMTP Authentication Support
Set your gmail and google app information.
If you want to use Gmail as SMTP server,
SMTP server: smtp.gmail.com
SMTP port: 465
Use encrypted protocol: Use SSL
SMTP Authentication
Username : youremail@gmail.com or ouremail@yourGoogleAppsDomainName.com(google app)
Password : yourpassword
Note : Remove leading and trailing space from "SMTP Authenitcation Username" if is there otherwise it's not authenticate your request to gmail.