experchange > php

Clint.Miller1 (08-14-09, 04:21 PM)
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 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?
bill (08-14-09, 09:06 PM)
Clint.Miller1 wrote:
[..]
> 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
Clint.Miller1 (08-14-09, 11:39 PM)
On Aug 14, 2:06 pm, bill <nob> wrote:
> Clint.Mill...@gmail.com wrote:
> 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 (
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.
Jerry Stuckle (08-15-09, 01:34 AM)
Clint.Miller1 wrote:
> On Aug 14, 2:06 pm, bill <nob> wrote:
> 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 (
> 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?
Clint.Miller1 (08-15-09, 02:45 AM)
On Aug 14, 6:34 pm, Jerry Stuckle <jstuck> wrote:
> Do you have OpenSSL installed correctly on your local system?


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.
Jerry Stuckle (08-15-09, 03:03 AM)
Clint.Miller1 wrote:
> On Aug 14, 6:34 pm, Jerry Stuckle <jstuck> wrote:
> 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.
Clint.Miller1 (08-16-09, 04:08 PM)
On Aug 14, 8:03 pm, Jerry Stuckle <jstuck> wrote:
> 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.
Jerry Stuckle (08-16-09, 09:01 PM)
Clint.Miller1 wrote:
[..]
> () 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.
Clint.Miller1 (08-16-09, 09:45 PM)
On Aug 16, 2:01 pm, Jerry Stuckle <jstuck> wrote:
[..]
> 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!
luis.ssilva.197809 (10-30-15, 01:51 PM)
Hi Tehere,

Did you solve this situation I got the same problem.

On Friday, August 14, 2009 at 3:21:01 PM UTC+1, Clint....@gmail.com wrote:
[..]
luis.ssilva.197809 (10-30-15, 01:52 PM)
Hi there,

I got the same problem is there anyway that you solved this problem ?

On Friday, August 14, 2009 at 3:21:01 PM UTC+1, Clint....@gmail.com wrote:
[..]
raghav.zwt (02-05-16, 03:52 PM)
Hi Tehere,

Did you solve this situation I got the same problem
gwwprogrammer (01-15-20, 08:50 AM)
On Friday, August 14, 2009 at 7:51:01 PM UTC+5:30, Clint....@gmail.com wrote:
[..]
kristjanman2k20 (03-04-20, 03:43 PM)
reede, 14. august 2009 17:21.01 UTC+3 kirjutas Clint....@gmail.com:
[..]
> 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?


I don't see why people want to make things so difficult.
Could just put a link to webpage that will open their mail portal.

Kristjan Robam
Jerry Stuckle (03-04-20, 06:09 PM)
On 3/4/2020 8:43 AM, kristjanman2k20 wrote:
> reede, 14. august 2009 17:21.01 UTC+3 kirjutas Clint....@gmail.com:
> I don't see why people want to make things so difficult.
> Could just put a link to webpage that will open their mail portal.
> Kristjan Robam


Because that exposes their email address. Spammers look for these types
of links and when found add them to a list they sell to other spammers.

Just a great way to get inundated with SPAM.

Similar Threads