0

I am trying to access my company mail id (the mail provider is Gmail) inbox using IMAP. I have applied almost all the possible solutions available here and also on google. But I am facing the same issue.

These are the some solutions which I tried,

  1. allow less secure app access Gmail
  2. enabled IMAP access from Gmail
  3. added novalidate-cert

Here's my code:

$hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$username = 'mymail@company.ae';
$password = 'mypassword';

// try to connect 
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Tiriyo: ' . 
imap_last_error());

Error message

Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX 
in \path\to\file\index.php on line 12

I don't see where I'm going wrong. Please help...

Anisha Krishnan
  • 21
  • 1
  • 10
  • 1
    Check whether there's a firewall that blocks your connection completely. – arnt Mar 25 '22 at 09:32
  • This is not a firewall problem. I am encountering the same problem on my dedicated root server. When I test the connection with telnet, the connection is working as it should. Only imap_open don't want to. ~ # telnet imap.gmail.com 993 Trying 2a00:1450:400c:c07::6c... Connected to imap.gmail.com. Escape character is '^]'. – Orgoth Dorngree Jun 08 '22 at 05:41

2 Answers2

2

Google has deactivated the regular login for third parties on 2022-05-31!

https://support.google.com/accounts/answer/6010255

It is now necessary to implement the Google PHP lib.

https://github.com/googleapis/google-api-php-client
https://github.com/googleapis/google-api-php-client/blob/main/docs/oauth-web.md

The option for less secure apps has also been removed by Google, which now also eliminates this possibility. https://myaccount.google.com/lesssecureapps

0

I ran into the same issue and solved it by generating an app-password for my application.

see: How can I read emails with Google Gmail?

Zoidberg
  • 1
  • 1