Gmail IMAP with PHP?

I am trying to connect to my Gmail account on PHP via IMAP, but I always get an error that says it cannot open the stream. I tried many different things to fix this but no luck. BTW, I am using 000webhost.com to host my site and they say they support IMAP. Here's my code:

$server="{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
$inbox = imap_open($server,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

      

For $ username and $ password, I am using Gmail email and password (e.g. myemail@gmail.com and mygmailpassword) Any ideas?

+3


source to share


1 answer


In GMAIL, you must enable IMAP:



in your gmail account, go to: Settings -> Forwarding and POP / IMAP -> enable IMAP

+2


source







All Articles