0

I am trying to use PHPMailer to send an email. I am using the latest version (5.2.8) installed using Git. My PHP version is 5.5.11 and is running on Centos 6.4 with Apache 2.2. I am running the script provided under examples/gmail.php (also available at http://phpmailer.worxware.com/index.php?pg=examplebgmail) except that I changed my username and password to my actual gmail credentials. My gmail credentials work with PHPMailer 5.0.0.

When running the script, I get the following error:

SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
SMTP connect() failed.
Mailer Error: SMTP connect() failed. 

If I run the script in my PhpED IDE, I get exception SMTP connection() failed from line 1195 in class.phpmailer.php (line 1195 is shown below).

if (!$this->smtpConnect()) {
   throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
}

Per earlier answer Connection error with PHPMailer and SMTP: node name or service name not known, I tried the following with the following results:

[root@devserver ~]# nslookup smtp.gmail.com
Server:         192.168.0.1
Address:        192.168.0.1#53

Non-authoritative answer:
smtp.gmail.com  canonical name = gmail-smtp-msa.l.google.com.
Name:   gmail-smtp-msa.l.google.com
Address: 173.194.79.108
Name:   gmail-smtp-msa.l.google.com
Address: 173.194.79.109

[root@devserver ~]#

[Michael@devserver ~]$ ping smtp.gmail.com
PING gmail-smtp-msa.l.google.com (74.125.25.108) 56(84) bytes of data.
64 bytes from pa-in-f108.1e100.net (74.125.25.108): icmp_seq=1 ttl=47 time=18.6 ms

What is causing this error and how do I fix it? Thank you

Community
  • 1
  • 1
user1032531
  • 24,767
  • 68
  • 217
  • 387
  • Interesting. The error message that you are getting from phpmailer is indicating a DNS problem, but nslookup is resolving the name correctly. Out of curiosity, if you do `ping smtp.gmail.com` from the command line, does it resolve correctly, and does smtp.gmail.com respond? – mti2935 May 15 '14 at 00:36
  • It's a little surprising that ping (which uses getaddrinfo, like phpmailer uses) is returning a different IP than nslookup. But, they are both google IP addresses, so it could just be some round-robin DNS scheme that smtp.gmail.com is using. You're following the example at http://phpmailer.worxware.com/index.php?pg=examplebgmail, so you are trying to configure phpmailer to connect to smtp.gmail.com on port 587, correct? If so, from the command line, can you try, `telnet smtp.gmail.com 587`? Does it connect successfully? – mti2935 May 15 '14 at 16:54
  • http://stackoverflow.com/questions/42471693/phpmailer-using-gmail-gives-error/42472146?noredirect=1#comment72085437_42472146 –  Feb 26 '17 at 18:36

0 Answers0