imap_open : couldn't open stream to my mail server

TOZ picture TOZ · Apr 1, 2014 · Viewed 42.8k times · Source

Notice: Unknown: Connection failed to mail.domain.com,143: Connection timed out (errflg=2) in Unknown on line 0

imap_open("{mail.domain.com:143/novalidate-cert}INBOX", 'login', 'password')

The port 143 is open, I'm not behind a firewall, my server uses self-signed certificates.

I really don't understand why I can not connect to my mail server

I searched everywhere but I found no answer..

Answer

TOZ picture TOZ · Apr 2, 2014

Thank you for your answers. My mistake was not coming from the connection but rather a loop that crashed the server when I had too much email :

imap_open("{mail.domain.com:143/novalidate-cert}INBOX", 'login', 'password')

$mails = imap_search($stream, 'UNSEEN');

rsort($mails);
foreach ($mails as $mailId) {
  imap_fetch_overview($stream, $mailId, 0);
} //that was the mistake when email number is too big!