Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:// (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?


telnet 465

results to

Connected to
Escape character is '^]'.`


openssl s_client -connect

results to




results to


Non-authoritative answer:  canonical name =

Edit From this link ( 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?


migration rejected from May 14 '15 at 12:31

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off-topic by Sven May 14 '15 at 12:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – Sven
If this question can be reworded to fit the rules in the help center, please edit the question.

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 with no protocol or port specified. – Anthony Aug 26 '09 at 7:27
up vote 4 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

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.

The command returned CONNECTED. What could be the problem with my PHP setup? – Randell Sep 4 '09 at 8:15 What OS are you using ? What php version ? Try replacing 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)

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://';
$config['smtp_port'] = 465;
$config['smtp_user'] = '';
$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);
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.

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 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 Is it not – 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 -- Are you sure you have your resolvers (/etc/resolv.conf) setup correctly? Try SSH-ing to the server and running "nslookup"

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

I edited the question to reflect the result of nslookup 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.

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,,, 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.

 try {  
    $sock = @fsockopen($t['host'], $t['port'], $errno, $errstr,10);
    catch (Exception $e) {

        $sock =null ;
         return ;
Although the code is appreciated, it should always have an accompanying explanation. This doesn't have to be long but it is expected. – peterh May 14 '15 at 13:15

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