使用PHP连接到Gmail& IMAP [英] Connect to Gmail with PHP & IMAP
问题描述
我从 php.ini $中启用了
OpenSSL
和 IMAP
函数c $ c> file和 phpinfo()
证实它。
通过使用下面的代码,我可以连接到Hotmail帐户,但不是Gmail帐户(当然,我将 $ connect_to
更改为指向Hotmail。)
$ connect_to ='{imap.gmail.com:993/imap/ssl}INBOX';
$ connection = imap_open($ connect_to,$ user,$ password)
或die(无法连接到'$ connect_to':。imap_last_error());
imap_close($ connection);
返回的错误是
警告:imap_open():无法在第6行$ b中的/opt/lampp/htdocs/webmail_client_practise/index.php中打开流{imap.gmail.com:993/imap/ssl}INBOX $ b无法连接到'{imap.gmail.com:993/imap/ssl}INBOX':imap.gmail.com证书失败:无法获得本地发行者证书:/ C = US / O = GeoTrust Inc. / CN = GeoTrust Global CA
注意:未知:imap.gmail.com证书失败:无法获得本地签发者证书:/ C = US / O = GeoTrust Inc./CN=GeoTrust Global CA(errflg = 2 )in Unknown 0
不幸的是,我找不到如何使用IMAP函数的完整教程。
任何想法,解决方案或建议都会有所帮助。 更新:
在Internet上搜索我的问题后,我没有找到完全解决问题的解决方案。虽然如果
<1>我使用不安全的 $ connect_to ='{imap.gmail.com:993/imap/ssl/novalidate-cert} INBOX';
2)允许gmail被较少的安全应用程序访问
,
请检查 https://support.google.com/accounts/answer/6010255?hl=zh_CN
I have enabled OpenSSL
and IMAP
functions from my php.ini
file and phpinfo()
confirms it.
By using the code below i can connect to a Hotmail account but not to a Gmail account.(of course i change the $connect_to
to point to Hotmail.)
$connect_to = '{imap.gmail.com:993/imap/ssl}INBOX';
$connection = imap_open($connect_to, $user, $password)
or die("Can't connect to '$connect_to': " . imap_last_error());
imap_close($connection);
The returned error is
Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /opt/lampp/htdocs/webmail_client_practise/index.php on line 6
Can't connect to '{imap.gmail.com:993/imap/ssl}INBOX': Certificate failure for imap.gmail.com: unable to get local issuer certificate: /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
Notice: Unknown: Certificate failure for imap.gmail.com: unable to get local issuer certificate: /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA (errflg=2) in Unknown on line 0
Unfortunately i cannot find a complete tutorial of how to use the IMAP functions.
Any ideas, solutions or suggestions will be helpful.
UPDATE:
After searching for my problem on the Internet, i did not found a solution that solves my problem completely. Although if
1) I use the insecure $connect_to = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
2)And allow gmail to be accessed by less secured apps
,
solves my problem for now.
Please check this https://support.google.com/accounts/answer/6010255?hl=en
这篇关于使用PHP连接到Gmail& IMAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!