sudo apt-get install libc-client2007b libc-client2007b-dev
sudo apt-get install php5-imap
sudo /etc/init.d/apache2 restart
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?
Here is what I use: (note I am using pop, not imap so the port is
995)
$in=imap_open("{pop.gmail.com:995/pop3/ssl}","my-email-address",
"my-password");
$msgs=imap_headers($in); // gets the headers from the currently
available msgs
$nummessages =count($msgs);
also on ubuntu: 9.04
Thanks for the answer, but I get the exact same error with pop as
imap. I'm sure this is some configuration error with the php on my
computer, but I'm having a hard time tracking it down. I found one
blog (http://petewarden.typepad.com/searchbrowser/2008/03/how-to-use-
imap.html) where the author posted an example of how to connect to
gmail with imap. When I run his PHP code from his web site, it works
fine. But, when I run his PHP code from my local Apache, I get the
same error I get with my stuff.
Do you have OpenSSL installed correctly on your local system?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
Yes. My application issues GET requests to several sites that use SSL/
HTTPS, and those work just fine. Also, if I do an "apt-get install
openssl", I get a message saying it's at the latest level.
I should mention that I didn't build PHP myself but rather installed
it with apt-get. I'm going to try building it from scratch to see if
that makes a difference.
It's not just what's compiled in, but what extensions you have in your
php.ini file. Just look at phpinfo() to see what's actually configured.
When I do a phpinfo(), I get an openssl section with the following
values in it:
OpenSSL support: enabled
OpenSSL Version: OpenSSL 0.9.8g 19 Oct 2007
I don't have any extensions enabled in my php.ini file for OpenSSL.
But, from what I understand from several forum threads I've read,
OpenSSL support is automatically enabled in PHP on Ubuntu. Not sure
if that's true or not, but it does seem to match up with what phpinfo
() is showing me.
Also, my application is able to successfully perform GET operations on
HTTPS sites. So, SSL is working in general, just not for IMAP.
Just because it works for HTTPS does NOT mean it will work for other
things. Different operations require different requests, for instance.
And in this case the message is indicating an "SSL context failure" -
which points to OpenSSL (as opposed to, for instance, a port being
blocked). That and the fact the same code works on your server
indicates your PHP is correct. This is why I keep asking about OpenSSL.
I can think of no PHP options which would cause this specific error,
(although it still is possible). But what do you see when you compare
your local phpinfo() vs. your working phpinfo()?
And while you're at it - I'd suggest checking your openssl config
options between the two.
I built openssl and php from scratch rather than getting them with apt-
get, and the problem went away. Everything is working now.
Thanks to everyone for the input!