Question

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

Was it helpful?

Solution

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!

OTHER TIPS

In my case, this did the trick:

imap_open("{mail.domain.com:110/pop3/notls}INBOX", 'login', 'password')

My guess is that you are behind ssl (default port 993)

Try

imap_open("{mail.domain.com:993/imap/ssl/novalidate-cert}INBOX", 'login', 'password') or die('Cannot connect: ' . print_r(imap_errors(), true))

Dont forget to open that port

In my case, the imap extension was compiled without the --with-imap-ssl option. You need to pass it to configure or if you're using Docker:

docker-php-ext-configure imap --with-imap-ssl
docker-php-ext-install imap

You can verify if there is an SSL Support using this command:

php -i | grep imap -A 5

If there is no "SSL Support => enabled" string, you need to recompile the imap extension.

Lack of SSL Support was resulting in not very clear error messages:

Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX
Can't open mailbox {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX: invalid remote specification

I had the same issue for myself. As you can see.

enter image description here

So, How I solved this:

Go to Your Google Account, You have to change the Security Settings.

Go to Security Tab.

Scroll down and you will find Signing in to Google

Turn OFF these two settings:

  1. Use your phone to sign in
  2. 2-Step Verification

And Turn Less secure app access ON.

That's all, It worked for me and hope will work for you.

For yahoo email this is what work for me

imap_open( "{imap.mail.yahoo.com:993/imap/ssl/novalidate-cert}INBOX", "Email", "PASSWORD" );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top