Reputation: 2139
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..
Upvotes: 20
Views: 65984
Reputation: 774
For yahoo email this is what work for me
imap_open( "{imap.mail.yahoo.com:993/imap/ssl/novalidate-cert}INBOX", "Email", "PASSWORD" );
Upvotes: -1
Reputation: 117
I had the same issue for myself. As you can see.
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:
And Turn Less secure app access ON
.
That's all, It worked for me and hope will work for you.
Upvotes: 0
Reputation: 2139
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!
Upvotes: 12
Reputation: 1274
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
Upvotes: 1
Reputation: 1100
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
Upvotes: 1
Reputation: 149
In my case, this did the trick:
imap_open("{mail.domain.com:110/pop3/notls}INBOX", 'login', 'password')
Upvotes: 2