20

Apacheで実行されているPHPを使用してIMAP経由でGmailに接続しようとしています。これはUbuntu9.04システム上にあります。これが機能しない原因となる、ある種のPHP構成の問題があります。まず、PHP用にIMAPをセットアップするために私が行ったことは次のとおりです。

sudo apt-get install libc-client2007b libc-client2007b-dev
sudo apt-get install php5-imap
sudo /etc/init.d/apache2 start

phpinfo()を実行すると、次のimap値が得られます。

IMAP c-Client Version: 2004
SSL Support: enabled
Kerberos Support: enabled

これが私のサンプルコードです:

<?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);
?>

このコードを実行すると、次の出力が得られます。

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

このコンピューターからimap.gmail.com:993にtelnet接続できることに注意してください。また、Evolution(メールリーダー)をIMAP経由でGmailに接続し、問題なくメールを取得することもできます。したがって、これはファイアウォールの問題ではないと思います。PHPに正しくセットアップされていないものがあると確信しています。

何か案は?

4

10 に答える 10

11

PHPで有効にする必要があるもう1つの追加機能は、OpenSSL拡張機能です。IMAPクライアントライブラリ(SSL付き)はこれに依存しているようです。

リクエストがPHPに渡される前に処理/処理されるため、ApacheでOpenSSLモジュールが有効になっているかどうかは関係ありません。

次のディスカッションスレッドは、いくつかの光を当てるのに役立つ可能性があります。

http://groups.google.com/group/comp.lang.php/browse_thread/thread/241e619bc70a8bf4/bd3ae0c6a82409bc?lnk=raot&pli=1

于 2009-08-17T21:24:51.583 に答える
10

これは長い努力の後で私のために働きました:

$ServerName = "{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox";
于 2009-11-09T16:56:07.503 に答える
8

私は同じ問題に直面していました。WindowsとWampを使用していて、Wampの「openSSl」拡張機能が有効になっています。

次の手順でこの問題を解決しました。これがあなたにも役立つことを願っています。

1)ブラウザ経由でGmailアカウントにログインしました。

2)このURLを開きます " https://www.google.com/settings/security/lesssecureapps "

3)「オンにする」をクリックします

4)次のコードを試してください

<?php

set_time_limit(4000);


// Connect to gmail
//$imapPath = '{imap.gmail.com:993/imap/ssl}INBOX';
$imapPath = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$username = 'your-emai-address@gmail.com';
$password = 'Your-password';

// try to connect
$inbox = imap_open($imapPath,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
   /* ALL - return all messages matching the rest of the criteria
    ANSWERED - match messages with the \\ANSWERED flag set
    BCC "string" - match messages with "string" in the Bcc: field
    BEFORE "date" - match messages with Date: before "date"
    BODY "string" - match messages with "string" in the body of the message
    CC "string" - match messages with "string" in the Cc: field
    DELETED - match deleted messages
    FLAGGED - match messages with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set
    FROM "string" - match messages with "string" in the From: field
    KEYWORD "string" - match messages with "string" as a keyword
    NEW - match new messages
    OLD - match old messages
    ON "date" - match messages with Date: matching "date"
    RECENT - match messages with the \\RECENT flag set
    SEEN - match messages that have been read (the \\SEEN flag is set)
    SINCE "date" - match messages with Date: after "date"
    SUBJECT "string" - match messages with "string" in the Subject:
    TEXT "string" - match messages with text "string"
    TO "string" - match messages with "string" in the To:
    UNANSWERED - match messages that have not been answered
    UNDELETED - match messages that are not deleted
    UNFLAGGED - match messages that are not flagged
    UNKEYWORD "string" - match messages that do not have the keyword "string"
    UNSEEN - match messages which have not been read yet*/

// search and get unseen emails, function will return email ids
$emails = imap_search($inbox,'UNSEEN');

$output = '';

foreach($emails as $mail) {

    $headerInfo = imap_headerinfo($inbox,$mail);

    $output .= $headerInfo->subject.'<br/>';
    $output .= $headerInfo->toaddress.'<br/>';
    $output .= $headerInfo->date.'<br/>';
    $output .= $headerInfo->fromaddress.'<br/>';
    $output .= $headerInfo->reply_toaddress.'<br/>';

    $emailStructure = imap_fetchstructure($inbox,$mail);
    //var_dump($emailStructure->parts);
    if(isset($emailStructure->parts)) {
         $output .= imap_body($inbox, $mail, FT_PEEK);
    } else {
        //    
    }
   echo $output;
   $output = '';
}

// colse the connection
imap_expunge($inbox);
imap_close($inbox);


?>

幸運を祈ります。:)

于 2016-05-27T08:28:42.593 に答える
3

Googleアプリの個人ドメインでも同じ問題が発生しました。アカウントへのアプリケーションアクセスを変更することで問題が解決しました。リンクをたどって、アカウントへのアクセスをオンにするだけです。

于 2015-10-01T14:43:02.553 に答える
2

GmailのIMAPサーバーに固有:

Googleは、SNIホスト名を提供しないTLSv13接続に対して無効な証明書を返し始めました。これにより、アップグレードされたOpenSSL(libssl)バージョンに対してphp-imap拡張機能を構築するときにリグレッションが発生します。問題はすでにここで報告されています:

後者はごく最近のものであり、LTSバージョンであるUbuntu Bionicに影響を与えるため、Ubuntuのメンテナーに提出して、彼らに見えるようにし、より多くの人の目を引き付けることを願っています。

視認性を高めるために、投票および/またはコメントしてください。また、この回答が有用であり、十分に賛成されている場合は、上記の問題がさらに明確になります。

それまでの間、バグが修正されるまでの唯一の回避策は、セキュリティ上のリスクであるimap_open()/novalidate-certを呼び出すときにフラグを使用して証明書の検証を無効にすることです。

于 2019-06-26T15:16:35.373 に答える
1

コマンドラインからコードを実行し、phpが他のエラーを吐き出すかどうかを確認します。

php -f gmail.php

私のUbuntuで私はしました:

sudo apt-get install php-imap

PHPとインストールされたシステムにimapをインストールするには: libc-client2007b mlock libc-client2007b mlock php-imap

次に、php5をアンインストールして、クリーンに再インストールします。

于 2009-08-16T18:15:56.410 に答える
0

で設定を確認し、リストに表示されているphpinfo()ことを確認してください--with-imap-ssl

于 2009-08-14T19:20:12.103 に答える
0

Gmailでこれに問題が解決しない場合は、Googleアカウントのセキュリティ設定ページで[安全性の低いアプリへのアクセスを許可する]を有効にしてください。

于 2015-09-22T13:19:30.073 に答える
0
  1. まず、Gmailアカウントで安全性の低いアプリを有効にします: https ://myaccount.google.com/lesssecureappsここに画像の説明を入力してください

  2. この構成を使用して、IMAP接続を作成します。

    $imap_connection = imap_open('{imap.gmail.com:993/imap/ssl/novalidate-
    cert}INBOX', 'YOUR GMAIL USER', 'YOUR GMAIL PASSWORD');
    

:INBOXはメインの受信トレイです。たとえば、接続でINBOX.Sentを使用して送信済みアイテムにアクセスできます。

于 2017-05-26T21:39:56.280 に答える
0

私はArvindGondaliyaです、あなたは正しいですが、安全性の低いエリアがオフの場合は、Gmailメールを取得します。

于 2020-01-15T06:57:09.297 に答える