WordPress is the most widely used CMS for websites. Sending out mails from WordPress is required in scenarios such as contact form submissions or password resets.
‘SMTP connect() failed‘ is a commonly encountered error in WordPress, due to which emails fail to be send from your WordPress site.
Configuring email settings in WordPress
By Default, WordPress uses the PHP Mail function to send emails. But using PHP mail function is a less secure method and makes the server vulnerable to spamming.
As a result, many webservers have PHP mail() function disabled for security purposes. In those servers, mails can be send from WordPress using SMTP.
SMTP uses proper authentication and is therefore more secure. There are WordPress plugins such as ‘WP Mail SMTP‘, that has to be configured to send mails via SMTP.
Once the SMTP plugin is activated, a new ‘Email‘ menu will show up under the Settings in WP. You can configure the email delivery settings in that option.
You can give your email address, password, mail server name and port in the Email settings and save it. You can test the mail delivery to see if the settings are fine.
The following settings can be configured in the Email settings:
From Email - the email address you want to send emails from From Name - the name that your emails will be received from Mailer - you can choose between the default PHP Mail function and SMTP SMTP Host - the hostname for your SMTP server SMTP Port - the port for your mail server, usually 25 Encryption - if you want to enable SSL/TLS encryption for the mail server Authentication - check it for mail server authentication Username - the username for your SMTP server Password - the password for your SMTP server
What causes error ‘SMTP connect() failed’ in WordPress
The default mailer is PHPMailer in WordPress and many sites use it to send mails. But it can give ‘SMTP connect() failed’ error if PHPMailer is unable to contact the SMTP server.
Also, if the settings for the SMTP server is not configured correctly, it will not send mails successfully from the server and give ‘SMTP connect() failed’ error.
The error ‘SMTP connect() failed’ can be caused due to the many reasons, which we’ll discuss one by one.
Wrong username and password given in SMTP authentication. SMTP port blocked in mail server firewalls. SSL/TLS not support in mail server and encryption is enabled in WP setting. Security restrictions by 3rd party servers such as gmail or email apps. Upgrades to WordPress plugin or PHPMailer versions that have enhanced security features or bugs.
How to fix error ‘SMTP connect() failed’ in WordPress
To fix the error, first thing is to do is to identify the cause for the error, by checking and ruling out each possibility.
1. SMTP host and port settings
Enter the name of your mail server in ‘SMTP Host’ section. This is usually the ‘domain name’ or ‘mail.domain.com’. Make sure that the DNS for SMTP host resolves correctly.
Give port number as 25, the default SMTP port. For mail servers that use custom ports such as 587 for SMTP to avoid spamming, give that port.
It is also possible that certain mail servers restrict the access to their port 25 using firewall rules. In such cases, your IP should be white-listed in the firewall to avoid SMTP error.
To confirm that the connectivity to SMTP server and port is working fine, use the command:
telnet domain.com 25
Use the appropriate hostname and port number, after confirming that the SMTP connection is working fine.
If the connectivity fails to establish, mail delivery will fail with the error ‘SMTP connect() failed‘.
2. SMTP authentication details
Every mail server has an authentication system to validate the users before allowing them to connect to it and send mails. In your WordPress Email settings, enter these details.
Give the email account username and password. Enter the full ‘user@domain.com’ as the username in case of non-default accounts.
Whenever the email account password is changed or updated for security reasons, do not forget to change the password in ‘Email settings’ also.
If the authentication details given are wrong, WordPress will fail to send mails and give the error ‘SMTP connect() failed‘.
3. SMTP encryption settings
For secure email transmission, it is always advisable to choose SMTP with encryption. This can be done using ‘Use SSL encryption’ option in WordPress setting.
But is some email servers, this SSL/TLS support may not be enabled. In those cases, if you choose encryption, mails may not get delivered.
Make sure that the ‘openssl’ utility is configured properly in your email server. Also, verify the SSL certificate for your mail server, using the command:
openssl s_client -starttls smtp -crlf -connect mail.domain.com:25
Using expired or self-signed certificates can cause the mail delivery using SSL to fail and give error ‘SMTP connect() failed‘.
So the solution in those cases is to configure SSL for your mail server properly or change the SMTP encryption to ‘No Encryption’, which is less secure one.
4. Support for 3rd party apps
Gmail servers have a lot of security restrictions in place, which may cause them to block attempts from certain mail client apps.
In those cases, you will have to loosen the security measures. In gmail, go to ‘My Account’ -> ‘Less Secure Apps‘ section, and turn on the option ‘Access for less secure apps‘.
If you are using Gmail as your mail server, then a better option is to install and activate the ‘Gmail SMTP’ plugin for WordPress.
5. WordPress SMTP plugins
Lastly, the SMTP plugin related issues can also cause ‘SMTP connect failed’ error. In those cases, you will have to stop using ‘WP Mail SMTP’ plugin and choose other ones.
Some WordPress SMTP plugins that can be used are Postman SMTP Mailer, Mailgun, etc. for sending mails from WordPress sites.
In short..
Other variants for ‘SMTP connect() failed’ error are ‘Called Mail() without being connected’ or ‘SMTP Error: Could not connect to SMTP host.’
In addition to the configuration settings we’ve discussed, one important point to keep in mind is the safety precautions to take during WordPress or PHPMailer upgrades.
At Bobcares, our hands-on experience with both WordPress customization and server administration has helped us to perform upgrades and fixes in websites without causing any business downtime.
If you’d like to know how to secure and manage your servers and customize your websites to prevent errors, we’d be happy to talk to you.
what if we only use php code without plugin wordpress? it is still possible to smtp connect? please help
Venator,
It is possible to send mails via smtp function using PHP scripts too. Please submit your details at https://bobcares.com/contact-us/ and we would help you configure the mail delivery settings of your PHP script.
I face the same issue, the mail is not send. What i have to do,
Facing the same issue. Emails were working as they should be.
I have uploaded a ssl certificate to my webpage and email aren’t sent neither to customer nor to me. But in my local machine everything works okay.