通过使用PHP的IMAP连接到Gmail - SSL上下文失败 [英] Connecting to Gmail through IMAP with PHP - SSL context failed

查看:218
本文介绍了通过使用PHP的IMAP连接到Gmail - SSL上下文失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用运行在Apache中的PHP的IMAP连接到Gmail。这是在Ubuntu 9.04系统上。我有一些PHP配置问题,使这从工作。首先,这里是我为PHP设置IMAP所做的:

  sudo apt-get install libc-client2007b libc-client2007b-dev 
sudo apt-get install php5-imap
sudo /etc/init.d/apache2 start

运行phpinfo()时,我得到以下imap值:

  IMAP c-Client版本:2004 
SSL支持:已启用
Kerberos支持:已启用

以下是我的示例代码:

 <?php 
$ connect_to ='{imap.gmail.com:993/imap/ssl/novalidate-证书} INBOX';
$ user ='我的Gmail地址';
$ password ='我的gmail密码';

$ connection = imap_open($ connect_to,$ user,$ password)
或die(无法连接到'$ connect_to':。imap_last_error());

imap_close($ connection);
?>

当我执行这段代码时,我得到以下输出:

 警告:imap_open()[function.imap-open]:无法打开流{imap.gmail.com:993/imap/ssl/novalidate-cert}第10行的/var/www/clint/gmail/gmail.php中的INBOX 
无法连接到'{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX':TLS / SSL imap.gmail.com失败:SSL上下文失败

请注意,我可以telnet到imap.gmail。 com:993从这台电脑。我还可以通过IMAP将Evolution(邮件阅读器)连接到Gmail,并在没有问题的情况下获取邮件。所以,我不认为这是一个防火墙问题。



有什么想法?

解决方案

您需要在PHP中启用另外一件事,是 OpenSSL扩展。看起来,IMAP客户端库(使用SSL)依赖于此。



Apache是​​否启用OpenSSL模块并不重要,因为它在请求已交给PHP。



以下讨论主题可能有助于阐明:

http://groups.google。 com / group / comp.lang.php / browse_thread / thread / 241e619bc70a8bf4 / bd3ae0c6a82409bc?lnk = raot& pli = 1

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

When I run phpinfo(), I get the following imap values:

IMAP c-Client Version: 2004
SSL Support: enabled
Kerberos Support: enabled

Here's my sample code:

<?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

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.

Any ideas?

解决方案

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.

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上下文失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆