Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm getting this error on my local machine when sending emails using (gmail's smtp + PHPMailer + CodeIgniter), which I wasn't getting on our previous office (we had to move offices).

Severity: Warning

Message: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

Severity: Warning

Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution)

Additional info:

  • I already asked our sysad to open port 465, but I'm still getting the error
  • I tested the same app deployed in another server and it is working there
  • I didn't change any configurations in my local machine
  • I already forwarded the outside interface's port 465 to my machine's IP
  • Opened accesses to port 465 to my IP

I was wondering whether this error has something to do with the change in the network setup. What are the possible causes of this error? Also, what are the possible solutions?

Edit:

telnet smtp.gmail.com 465

results to

Trying 74.125.127.109...
Connected to smtp.gmail.com.
Escape character is '^]'.`

Edit

openssl s_client -connect smtp.gmail.com:465

results to

CONNECTED

Edit

nslookup smtp.gmail.com

results to

Server:     171.103.2.3
Address:    171.103.2.3#53

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

Edit From this link (http://bugs.php.net/bug.php?id=11058) posted by sh1ny, it was mentioned that restarting apache fixes the problem. It worked for me. But I still do not understand why. Got clues?

share|improve this question

migrated from stackoverflow.com Aug 28 '09 at 7:07

This question came from our site for professional and enthusiast programmers.

    
Have you tried sending email via a regular email client using that connection info? Narrow it down to either something within your application stack or something in the OS/network or beyond. –  Dav Aug 26 '09 at 6:50
    
The server that executes the script can't connect, so the error shouldn't have anything to do with your local machine, unless they are one in the same. If your server is on the same network as your local machine, try pinging that address from a command line. –  Anthony Aug 26 '09 at 7:23
    
Oh, and on my machine (personal, not server), I get ping errors on anything I've tried except for smtp.gmail.com with no protocol or port specified. –  Anthony Aug 26 '09 at 7:27

7 Answers 7

up vote 2 down vote accepted

To try if you have connectivity from you server to gmail's smtp over ssl i would suggest trying :

openssl s_client -connect smtp.gmail.com:465

If this works, the problem is in your php setup.

Forwarding external 465 and 25 to your IP doesn't do you any good, as you are trying to send, not recieve.

share|improve this answer
    
The command returned CONNECTED. What could be the problem with my PHP setup? –  Randell Sep 4 '09 at 8:15
    
bugs.php.net/bug.php?id=11058 What OS are you using ? What php version ? Try replacing smtp.gmail.com with an ip. Ask your sysadmin if the server running the php can do recursive dns queries through your dns servers ? –  sh1ny Sep 4 '09 at 9:59
    
Fedora 11, PHP 5.2.9. I'm using my local machine. I'll check out the bug and get back to you with my findings. Thanks! –  Randell Sep 4 '09 at 10:11
    
It was mentioned that restarting apache fixes the problem. It worked for me. But I still do not understand why. –  Randell Sep 8 '09 at 3:20

Seems like something's firewalling off your connections, and restricting access of the host/app/user to only be able to access certain things.

You need to check from the server whether you can connect, which I doubt you'll be able to.

Speak to your systems admin and ask him to allow OUTBOUND connections for the connection you're trying to make (you've asked him to unblock the port, he may have mistook that for incoming)

share|improve this answer
    
Sysad told me that outbound connections are already allowed. How do I disprove it aside from the error that I'm getting? –  Randell Aug 26 '09 at 9:21

Make sure you have openssl enabled as a PHP extension.

Double check your config.php file. It should contain this:

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'youremailaddress@gmail.com';
$config['smtp_pass'] = 'yourpassword';

When you initialize the email library make sure you pass the $config array as the second parameter. Also make sure you run the set_newline method as shown below. I don't know why you need to do that, perhaps somebody could elaborate.

$this->load->library('email', $config);
$this->email->set_newline("\r\n");
share|improve this answer
    
I'm using PHPMailer. –  Randell Sep 4 '09 at 8:26

You need to check that you are actually able to connect over SSL. Does your PHP script handle the SSL handshake? Try using stunnel to tunnel a local port 25 connection to the remote port 465. That may work.

share|improve this answer
    
Could you explain more about this? –  Randell Sep 4 '09 at 7:29
    
Seems like your error message has changed to a name resolution error. This means that php fails to resolve the name. Try setting the ip address for smtp.googlemail.com manually in /etc/hosts on the server and restart the web-server to use it. –  sybreon Sep 4 '09 at 8:50
    
People keep on saying smtp.googlemail.com. Is it not smtp.gmail.com? –  Randell Sep 4 '09 at 9:37

Anyone noticed the error was "php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution" ?

PHP can't resolve smtp.gmail.com -- Are you sure you have your resolvers (/etc/resolv.conf) setup correctly? Try SSH-ing to the server and running "nslookup smtp.gmail.com"

I think that's your problem, or try connecting to the IP and see what happens.

share|improve this answer
    
I edited the question to reflect the result of nslookup smtp.gmail.com. What does it mean? –  Randell Sep 4 '09 at 8:39

I'm pretty sure gmail uses 587 as their smtp port...465 should work too but try both.

share|improve this answer
    
587 and 465 works. –  Randell Sep 9 '09 at 23:59

This problem may be a result of enabling IPv6 support in the operating system. I saw this problem pop up suddenly when my host enabled IPv6. PHP has multiple known bugs in dealing with IPv6.

PHPMailer uses the PHP fsockopen() function with this known bug.

The problem is that fsockopen() doesn't detect that a connection was actively refused and instead times out on it.

The problem scenario occurs when the host has both ipv4 and ipv6 addresses (e.g,, smtp.gmail.com), the service is only listening on ipv4 but ipv6 has precedence results in:

  1. trying IPv6
  2. time out
  3. fail

instead of:

  1. trying IPv6
  2. connection refused
  3. trying IPv4
  4. success

If this is the problem, you can work around it by setting the IP address directly in the PHPMailer settings or in /etc/hosts as sybreon suggested. The problem still exists (at least) in PHP v5.3.2.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.