Getting Error like imap_open(): Couldn't open

2019-07-09 04:02发布

问题:

To fetch gmail mails, i am using below code. it is working fine in local, but i am getting error in server like :

Warning: imap_open(): Couldn't open stream {imap.googlemail.com:993/imap/ssl/novalidate-cert}INBOX in C:\xampp\htdocs\criticaloglive\email_real.php on line 10 Cannot connect to Gmail: Too many login failures

Here's my code :

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

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

回答1:

Use the $hostname instead of $server. also try with not secure imap with port 143

$inbox = imap_open($hostname,$username,$password) ;

this code works for me.



标签: php gmail imap