Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Connecting to Gmail through IMAP with PHP - SSL context failed

20,215 views
Skip to first unread message

clint....@gmail.com

unread,
Aug 14, 2009, 10:21:01 AM8/14/09
to
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

unread,
Aug 14, 2009, 3:06:29 PM8/14/09
to

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....@gmail.com

unread,
Aug 14, 2009, 5:39:16 PM8/14/09
to
On Aug 14, 2:06 pm, bill <nob...@spamcop.net> 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 (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.

Jerry Stuckle

unread,
Aug 14, 2009, 7:34:44 PM8/14/09
to

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

clint....@gmail.com

unread,
Aug 14, 2009, 8:45:09 PM8/14/09
to
On Aug 14, 6:34 pm, Jerry Stuckle <jstuck...@attglobal.net> 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

unread,
Aug 14, 2009, 9:03:13 PM8/14/09
to

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....@gmail.com

unread,
Aug 16, 2009, 10:08:47 AM8/16/09
to
On Aug 14, 8:03 pm, Jerry Stuckle <jstuck...@attglobal.net> 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

unread,
Aug 16, 2009, 3:01:17 PM8/16/09
to

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....@gmail.com

unread,
Aug 16, 2009, 3:45:04 PM8/16/09
to
On Aug 16, 2:01 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:

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.ssil...@gmail.com

unread,
Oct 30, 2015, 7:51:27 AM10/30/15
to
Hi Tehere,

Did you solve this situation I got the same problem.

luis.ssil...@gmail.com

unread,
Oct 30, 2015, 7:52:35 AM10/30/15
to
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:

ragha...@gmail.com

unread,
Feb 5, 2016, 8:52:20 AM2/5/16
to
Hi Tehere,

Did you solve this situation I got the same problem

gwwpro...@gmail.com

unread,
Jan 15, 2020, 1:50:47 AM1/15/20
to

kristja...@gmail.com

unread,
Mar 4, 2020, 8:43:30 AM3/4/20
to
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

unread,
Mar 4, 2020, 11:09:40 AM3/4/20
to
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.


--
==================
Remove the "x" from my email address
Jerry Stuckle
jstu...@attglobal.net
==================

Kristjan Robam

unread,
Mar 4, 2020, 3:50:20 PM3/4/20
to
Gmail is pretty known portal.
Forgive me if I didn't get your point.
If you find gmail link, there is nothing special about this.

Kristjan Robam

Jerry Stuckle

unread,
Mar 4, 2020, 4:57:24 PM3/4/20
to
It gives spammers a valid email address to spam - worth much more than
just a portal. And serious users don't use gmail addresses - they have
email addresses on their own domains.

Kristjan Robam

unread,
Mar 4, 2020, 4:59:50 PM3/4/20
to
No, I didn't mean that. I mean't that you write only gmail . google . com link to your webpage. For faster access....

> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> jstu...@attglobal.net
> ==================

Kristjan Robam

Jerry Stuckle

unread,
Mar 4, 2020, 9:05:51 PM3/4/20
to
> Kristjan Robam
>

That is not a valid email address and does not allow the user to send
you email.

Kristjan Robam

unread,
Mar 5, 2020, 1:35:47 AM3/5/20
to
Yes, it allows.

> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> jstu...@attglobal.net
> ==================

Kristjan Robam

Tony Mountifield

unread,
Mar 5, 2020, 5:48:26 AM3/5/20
to
In article <00b3f9b8-77c7-4537...@googlegroups.com>,
<kristja...@gmail.com> 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.

Any particular reason you are replying to a post that is over 10 years old?

Cheers
Tony

--
Tony Mountifield
Work: to...@softins.co.uk - http://www.softins.co.uk
Play: to...@mountifield.org - http://tony.mountifield.org

Arno Welzel

unread,
Mar 5, 2020, 11:55:10 AM3/5/20
to
On 04.03.20 17:09, Jerry Stuckle wrote:

> On 3/4/2020 8:43 AM, kristja...@gmail.com wrote:
>> reede, 14. august 2009 17:21.01 UTC+3 kirjutas Clint....@gmail.com:
[...]
>>> 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?
>>
>> 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.

I think there is a lot of misunderstanding her:

What has "I can't get IMAP access to GMail working with PHP" to do with
"put a link to the mail portal"?

And what does "put a link to the mail portal" to do with "put an e-mail
address to your website"?



--
Arno Welzel
https://arnowelzel.de

Arno Welzel

unread,
Mar 5, 2020, 11:58:40 AM3/5/20
to
You all don't understand each other!

1) The OP asked how to get IMAP ACCESS WITH PHP TO GMAIL

2) Some other guy suggested to PUT A LINK TO THE GMAIL WEBSITE INSTEAD
OF USING IMAP IN PHP ITSELF

3) And some other complained the PUTTING AN EMAIL ADDRESS ON THE WEBSITE
might be bad since spammers will collect this address

This all has NOTHING in common except that you somehow talk about "email".

Kristjan Robam

unread,
Mar 6, 2020, 1:18:59 AM3/6/20
to
neljapäev, 5. märts 2020 12:48.26 UTC+2 kirjutas Tony Mountifield:
> In article <00b3f9b8-77c7-4537...@googlegroups.com>,
> <kristja...@gmail.com> 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.
>
> Any particular reason you are replying to a post that is over 10 years old?
>
Maybe someone can find my reply useful.

Kristjan Robam

Kristjan Robam

unread,
Mar 6, 2020, 1:20:35 AM3/6/20
to
We just give our opinions in this topic.

Kristjan Robam

Arno Welzel

unread,
Mar 6, 2020, 3:46:14 AM3/6/20
to
Kristjan Robam:

> neljapäev, 5. märts 2020 12:48.26 UTC+2 kirjutas Tony Mountifield:
>> In article <00b3f9b8-77c7-4537...@googlegroups.com>,
>> <kristja...@gmail.com> 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.
>>
>> Any particular reason you are replying to a post that is over 10 years old?
>>
> Maybe someone can find my reply useful.

What is useful in this reply?

"Put a link to the webpage that will open their mail portal" is no
substitude for direct IMAP access.

For example: if you want to use IMAP to check for mails arriving on a
specific address and then process these mails by a script using a link
to the mail portal does not help.
0 new messages