Connecting to Gmail through IMAP with PHP - SSL context failed(使用 PHP 通过 IMAP 连接到 Gmail - SSL 上下文失败)
问题描述
我正在尝试使用在 Apache 中运行的 PHP 通过 IMAP 连接到 Gmail.这是在 Ubuntu 9.04 系统上.我遇到了某种 PHP 配置问题,导致它无法正常工作.首先,这是我为 PHP 设置 IMAP 所做的:
I'm trying to connect to Gmail through IMAP with PHP running in Apache. This is on an Ubuntu 9.04 system. I've got some sort of PHP configuration issue that is keeping this from working. First, here's what I did to setup IMAP for PHP:
sudo apt-get install libc-client2007b libc-client2007b-dev
sudo apt-get install php5-imap
sudo /etc/init.d/apache2 start
当我运行 phpinfo() 时,我得到以下 imap 值:
When I run phpinfo(), I get the following imap values:
IMAP c-Client Version: 2004
SSL Support: enabled
Kerberos Support: enabled
这是我的示例代码:
<?php
$connect_to = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$user = 'my gmail address';
$password = 'my gmail password';
$connection = imap_open($connect_to, $user, $password)
or die("Can't connect to '$connect_to': " . imap_last_error());
imap_close($connection);
?>
当我执行这段代码时,我得到以下输出:
When I execute this code, I get the following output:
Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX in /var/www/clint/gmail/gmail.php on line 10
Can't connect to '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX': TLS/SSL failure for imap.gmail.com: SSL context failed
请注意,我可以从这台计算机远程登录到 imap.gmail.com:993.我还可以通过 IMAP 将 Evolution(邮件阅读器)连接到 Gmail 并毫无问题地获取邮件.所以,我认为这不是防火墙问题.我很确定我在 PHP 中的某些内容设置不正确.
Note that I can telnet to imap.gmail.com:993 from this computer. I can also hookup Evolution (mail reader) to Gmail through IMAP and fetch mail without problems. So, I don't think this is a firewall issue. I'm pretty sure I've got something in PHP not setup correctly.
有什么想法吗?
推荐答案
您需要在 PHP 中启用的另一件事是 OpenSSL 扩展.IMAP 客户端库(带有 SSL)似乎依赖于此.
One more additional thing you need enabled in PHP, is the OpenSSL extension. It appears that the IMAP Client library (with SSL) depends on this.
Apache 是否启用了 OpenSSL 模块并不重要,因为在将请求移交给 PHP 之前已对其进行处理/处理.
It doesn't matter if Apache has the OpenSSL module enabled as this is processed/handled before the request is handed off to PHP.
以下讨论主题可能有助于阐明一些观点:
The following discussion thread may help shed some light:
http://groups.google.com/group/comp.lang.php/browse_thread/thread/241e619bc70a8bf4/bd3ae0c6a82409bc?lnk=raot&pli=1
这篇关于使用 PHP 通过 IMAP 连接到 Gmail - SSL 上下文失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 PHP 通过 IMAP 连接到 Gmail - SSL 上下文失败


基础教程推荐
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01