“SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed”. Well, this is how my week started. One of my client’s website running WordPress and Easy WP SMTP plugin failed to send mails. Though I rechecked all the mail configurations, test mails via Easy WP SMTP failed with the above error followed by “Name or service not known (0)SMTP connect() failed”. I could solve the issue after an hour of debugging.
Error : Failed to connect to server: php_network_getaddresses: getaddrinfo failed
This error can occur due to two reasons. One, there might me an issue with your DNS settings and second, PHP may not be able to get the network addresses for a given host/domain name.
To start with, I checked the mail settings in Easy WP SMTP plugin and everything was fine. Next, I contacted my DNS provider and confirmed that the issue is not with DNS. So it means, the issue boils down to PHP and as I rightly guessed, PHP was not able to resolve domain names. For example, while debugging, I thought the issue might be due to an outdated Easy WP SMTP plugin, so I decided to update the plugin to only see the error “wordpress.org : Name or service not known”.
It means, for some reason PHP was not able to get the network addresses of the given domain name. To confirm that the issue is with PHP, I wrote a small script as shown below:
<?php $ip = gethostbyname('www.google.com'); echo $ip; ?>
gethostbyname will get the IPv4 address corresponding to the given host name or prints back the host name on failure. In my case, the output was an unmodified host name. It means,
gethostbyname has failed to get the IP address of the given host name and that was the culprit.
All I did to fix the issue was to restart the
php-fpm daemon and everything worked fine. Unfortunately, I couldn’t find what caused php-fpm to fail, but more often restarting the daemon fixes many issue. Hope it helps someone in need.
Comments Leave a Comment
Thank you. I was tearing my hair out what was going on, but restarting php-fpm did the trick. Still don’t really understand it, but glad it’s working now.