PHP IMAP - Connection Failed

I have successfully setup an email server for myself using this DO tutorial for Postfix, Dovecot, MySQL, and RoundCube. I skipped spamassasin. Everything works fine, I can send and receive emails, and manage them through roundcube or my iphone.

But now I have spent 8 hours on this PHP problem, here’s the simplest I can reproduce it…

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

$mbox = imap_open("{localhost:143/imap}", "", "johnspassword", OP_HALFOPEN);

Gives the errors

Warning: imap_open(): Couldn't open stream {localhost:143/imap} in /var/www/ on line 6
Notice: Unknown: Connection failed to localhost,143: Connection refused (errflg=2) in Unknown on line 0

That is the error that shows for the php output. I can’t seem to find a log file with the same information. All I want is to connect to my emails.


port 993 has the same issue. I found the log file, nothing helpful there either. Up to about 10 hours of work on this now… Any guidance would be GREATLY appreciated.

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello friend!

This is definitely an interesting one because from the way it sounds on one end, IMAP services are up and running. From the other end, sounds like they may not be. There’s some clear disconnect there, so perhaps the configuration is more complex than average.

I would install telnet on the server and run this: telnet localhost 143

It’s just a quick way to see what you get when connecting to the port to/from localhost. A firewall entry could be blocking the internal connection (odd but possible). I can’t think of what else it could be, to be honest, that would cause external connections to succeed and internal ones to fail in relation to dovecot.

Kind Regards, Jarland