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 to host my site and they say they support IMAP. Here's my code:

$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. and mygmailpassword) Any ideas?


source to share

1 answer

In GMAIL, you must enable IMAP:

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



All Articles