[SOLVED] could not connect to localhost:143: php_network_getaddresses: getaddrinfo failed

This issue generally came with webmail issues in cpanel or directadmin servers (roundcube , squirrel mail ,etc,.)

So to solve this issue check the following.

1) Give 644 permissions to /etc/hosts , /etc/resolv.conf , /etc/host.conf

2) Give the following entry in /etc/hosts

127.0.0.1 localhost localhost.localdomain

3) Test if imap running on port 143 in server as following .

# telnet localhost 143
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE STARTTLS AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
^]
telnet> quit
Connection closed.

4) Restart webserver that configured with the webmail ( cpanel ,apache ,etc,. )

5) Now try to logins to webmail , it will work fine.