通过php imap连接Gmail?本地发行人证书错误 [英] connect gmail through php imap? local issuer certificate error

查看:266
本文介绍了通过php imap连接Gmail?本地发行人证书错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 PHP 通过 IMAP 连接到Gmail帐户。我有一些工作代码,但试图建立连接时,我收到以下错误:


警告:imap_open()[function。 imap-open]:无法在第31行打开流{imap.gmail.com:993/ssl}[Gmail]/全部邮件/home/demoosiz/public_html/goqlue/email.php

无法连接到Gmail:imap.gmail.com的证书失败:无法获得本地发行者证书:/ C = US / O = Google Inc / CN = Google互联网管理局


我的代码在下面

 <?php 
/ * connect to gmail * /
$ hostname ='{imap.gmail.com:993/ssl}[Gmail]/All Mail';
$ username ='hidden';
$ password ='hidden';
$ b $ *尝试连接* /
$ inbox = imap_open($ hostname,$ username,$ password)或die('无法连接到Gmail:'。imap_last_error());

/ *抓取电子邮件* /
$ emails = imap_search($ inbox,'ALL');
$ b $ *如果电子邮件被返回,则循环遍历每个... * /
if($ emails){

/ * begin输出var * /
$ output ='';

/ *将最新的电子邮件放在最上面* /
rsort($ emails);每个电子邮件
$ b $ * * /
foreach($ emails as $ email_number){

/ *获取特定于此电子邮件的信息* /
$ overview = imap_fetch_overview($ inbox,$ email_number,0);
$ message = imap_fetchbody($ inbox,$ email_number,2);

/ *输出邮件头信息* /
$ output。='< div class =toggler'。($ overview [0] - > seen?'read': '未读') '>'。
$ output。='< span class =subject>'。$ overview [0] - > subject。'< / span> ;
$ output。='< span class =from>'。$ overview [0] - > from。'< / span>';
$ output。='< span class =date> on'。$ overview [0] - > date。'< / span>';
$ output。='< / div>';

/ *输出电子邮件正文* /
$ output。='< div class =body>'。$ message。'< / div>';
}

echo $ output;
}

/ *关闭连接* /
imap_close($ inbox);
?>


解决方案

这似乎是证书问题。



我不会告诉你证书的问题是什么,也不知道如何解决它。 然而,你可以通过忽略该问题禁用证书验证来让您的Gmail帐户面临攻击:

  $ hostname ='{imap.gmail.com:993/ssl/novalidate-cert}[Gmail]/All Mail'; 


I need to connect to a Gmail account via IMAP using PHP. I have some working code, but when attempting to establish a connection, I receive the following error:

Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/ssl}[Gmail]/All Mail in /home/demoosiz/public_html/goqlue/email.php on line 31
Cannot connect to Gmail: Certificate failure for imap.gmail.com: unable to get local issuer certificate: /C=US/O=Google Inc/CN=Google Internet Authority

my code is below

<?php
    /* connect to gmail */
    $hostname = '{imap.gmail.com:993/ssl}[Gmail]/All Mail';
    $username = 'hidden';
    $password = 'hidden';

    /* try to connect */
    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

    /* grab emails */
    $emails = imap_search($inbox,'ALL');

    /* if emails are returned, cycle through each... */
    if($emails) {

      /* begin output var */
      $output = '';

      /* put the newest emails on top */
      rsort($emails);

      /* for every email... */
      foreach($emails as $email_number) {

        /* get information specific to this email */
        $overview = imap_fetch_overview($inbox,$email_number,0);
        $message = imap_fetchbody($inbox,$email_number,2);

        /* output the email header information */
        $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
        $output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
        $output.= '<span class="from">'.$overview[0]->from.'</span>';
        $output.= '<span class="date">on '.$overview[0]->date.'</span>';
        $output.= '</div>';

        /* output the email body */
        $output.= '<div class="body">'.$message.'</div>';
      }

      echo $output;
    } 

    /* close the connection */
    imap_close($inbox);
    ?>

解决方案

This seems to be a certificate issue.

I don't tell you what the certificate issue is nor how to solve it.

However, you can leave your gmail account open to attacks by ignoring that issue disabling the certificate validation:

$hostname = '{imap.gmail.com:993/ssl/novalidate-cert}[Gmail]/All Mail';

这篇关于通过php imap连接Gmail?本地发行人证书错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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