imap_open : couldn't open stream to my mail server
Asked Answered
W

6

20

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

Wallack answered 1/4, 2014 at 13:28 Comment(4)
what error are you getting?Lob
Cannot connect: Array ( [0] => Connection failed to mail.domain.com,143: Connection timed out )Wallack
this error occurs when server doesn't have IMAP Server running. If you are trying to connect gmail or any other mail server then you have to enable imap from settings. And if you have VPS then check you dovecot log.Lob
If you are using SSL, you likely need port 993. If you're using plaintext, it will be 143. If you're using STARTTLS, it will be 143. Can you telnet from you web host to mail.domain.com 143 and get a * OK prompt?Carolus
W
12

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!
Wallack answered 2/4, 2014 at 8:29 Comment(1)
Same problem when i try to download too big email it is showing.... imap_open(): Couldn't open stream {imap.gmail.com:123/imap/ssl}INBOX in,,,,,,,,,,,,,Cannot connect to Gmail: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser: support.google.com/mail/acco..........what mistake am i doing please let me knowLesterlesya
R
2

In my case, this did the trick:

imap_open("{mail.domain.com:110/pop3/notls}INBOX", 'login', 'password')
Recapitulation answered 11/6, 2019 at 15:47 Comment(0)
G
1

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

Germanous answered 1/4, 2014 at 13:35 Comment(3)
Your comments above contradict that: you say you have a self-signed certificate, which would only be useful for SSL.Carolus
Yes I'am sorry. I use SSL protocole but it uses self-signed certificates.Wallack
The default IMAP secure port is 993, not 585.Carolus
T
1

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
Teakwood answered 14/10, 2019 at 11:39 Comment(0)
K
0

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.

Kammerer answered 20/11, 2020 at 20:4 Comment(0)
D
-1

For yahoo email this is what work for me

imap_open( "{imap.mail.yahoo.com:993/imap/ssl/novalidate-cert}INBOX", "Email", "PASSWORD" );
Drislane answered 1/1, 2021 at 0:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.