Gmail的IMAP与PHP?

问题描述:

我试图通过IMAP连接到我的Gmail帐户,但是我总是收到一条错误消息,说它无法打开流。我已经尝试了很多不同的事情来解决这个问题,但我没有运气。顺便说一下,我使用000webhost.com来托管我的网站,他们说他们支持IMAP。这里是我的代码:

I'm trying to connect to my Gmail account in PHP via IMAP but I always get an error that says it can't open stream. I've tried lots of different things to fix this but I've had no luck. By the way, I'm using 000webhost.com to host my website and they say that 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());

对于$ username和$ password,我使用我的Gmail电子邮件和密码(例如myemail @ gmail.com和mygmailpassword)
任何想法?

For the $username and $password, I'm using my Gmail Email and password (e.g. myemail@gmail.com and mygmailpassword) Any ideas?

在GMAIL中,您必须启用IMAP:

In GMAIL you have to enable IMAP:

在您的Gmail帐户中,转到:设置 - >转发和POP / IMAP - >启用IMAP

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