file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known

故事扮演 提交于 2019-11-26 14:43:15

It means your server cannot connect to the outside world

This probably won't change anything given the DNS issues

So, If you have permission, try changing the name servers in your /etc/resolv.conf file to other nameservers.

There should be as well httpd allowed to connect outside. Check you selinux policy. this helps me to solve connection problem:

setsebool -P nis_enabled 1
setsebool -P httpd_can_network_connect 1

Here are advice in case you are using Docker env for your web app. I had same problem when I used docker php image, added dns options in yml file solved my problem.

docker-compose.yml

version: '2'

services:
  webserver:
    build: ./docker/webserver
    image: my_webapp
    dns: 8.8.8.8
    dns_opt:
      - use-vc
      - no-tld-query
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./:/var/www/html

In reference to one of the comments by @DUzun, and for those like myself who are familiar with the server in general but not a computer science major, I fixed the issue on Linux/Centos6 (Plesk Onyx) by:

1) Opening /etc/resolv.conf (my file was empty)

2) Added:

nameserver 8.8.8.8
nameserver 8.8.4.4

options rotate
options timeout:3

Hopefully this helps someone out there.

If you are using a name instead of an IP address in your smtp_host fsockopen() call, and your server cannot resolve that name into an IP address. If possible, find out the IP of the server you are trying to connect to, and use that instead. Hope so it will work fine. Example

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => '166.62.73.4', // mail.servername.com
    'smtp_port' => 587,
    'smtp_timeout' => '7',
    'smtp_user' =>'test@servername.com',
    'smtp_pass' => 'password',
    '_smtp_auth'   => false,
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1',
    'crlf' => '\r\n',
    'newline' => "\r\n"
            );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!