Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

Connecting to Gmail through IMAP with PHP - SSL context failed

瀏覽次數:20,444 次
跳到第一則未讀訊息

clint....@gmail.com

未讀,
2009年8月14日 上午10:21:012009/8/14
收件者:
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

未讀,
2009年8月14日 下午3:06:292009/8/14
收件者:

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

未讀,
2009年8月14日 下午5:39:162009/8/14
收件者:
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

未讀,
2009年8月14日 晚上7:34:442009/8/14
收件者:

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

未讀,
2009年8月14日 晚上8:45:092009/8/14
收件者:
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

未讀,
2009年8月14日 晚上9:03:132009/8/14
收件者:

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

未讀,
2009年8月16日 上午10:08:472009/8/16
收件者:
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

未讀,
2009年8月16日 下午3:01:172009/8/16
收件者:

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

未讀,
2009年8月16日 下午3:45:042009/8/16
收件者:
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

未讀,
2015年10月30日 清晨7:51:272015/10/30
收件者:
Hi Tehere,

Did you solve this situation I got the same problem.

luis.ssil...@gmail.com

未讀,
2015年10月30日 清晨7:52:352015/10/30
收件者:
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

未讀,
2016年2月5日 上午8:52:202016/2/5
收件者:
Hi Tehere,

Did you solve this situation I got the same problem

gwwpro...@gmail.com

未讀,
2020年1月15日 凌晨1:50:472020/1/15
收件者:

kristja...@gmail.com

未讀,
2020年3月4日 上午8:43:302020/3/4
收件者:
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

未讀,
2020年3月4日 上午11:09:402020/3/4
收件者:
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

未讀,
2020年3月4日 下午3:50:202020/3/4
收件者:
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

未讀,
2020年3月4日 下午4:57:242020/3/4
收件者:
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

未讀,
2020年3月4日 下午4:59:502020/3/4
收件者:
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

未讀,
2020年3月4日 晚上9:05:512020/3/4
收件者:
> Kristjan Robam
>

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

Kristjan Robam

未讀,
2020年3月5日 凌晨1:35:472020/3/5
收件者:
Yes, it allows.

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

Kristjan Robam

Tony Mountifield

未讀,
2020年3月5日 清晨5:48:262020/3/5
收件者:
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

未讀,
2020年3月5日 上午11:55:102020/3/5
收件者:
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

未讀,
2020年3月5日 上午11:58:402020/3/5
收件者:
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

未讀,
2020年3月6日 凌晨1:18:592020/3/6
收件者:
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

未讀,
2020年3月6日 凌晨1:20:352020/3/6
收件者:
We just give our opinions in this topic.

Kristjan Robam

Arno Welzel

未讀,
2020年3月6日 凌晨3:46:142020/3/6
收件者:
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 則新訊息