【问题标题】:Fetch unread mails from gmail apps从 gmail 应用程序中获取未读邮件
【发布时间】:2012-04-24 00:17:32
【问题描述】:

我正在尝试从 google 应用程序邮件帐户中获取未读邮件。

我一直在尝试以下脚本:

$email = 'name@domain.com';
$pass  = 'password';
$inbox = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', $email, $pass, NULL, 1) or die('Cannot connect to Gmail');

.. 但我收到以下错误:

Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /var/www/zvinx.dk/test/gmail.php on line 5
Cannot connect to Gmail

我已经联系了我的虚拟主机,他说 webhotel 支持 imap_open。有什么方法可以检查吗?

基本上,我如何使用 php 显示和标记已读邮件?

【问题讨论】:

    标签: php gmail imap


    【解决方案1】:

    PHP 的 imap_last_error() 和 imap_errors() 函数可能会告诉你发生了什么。

    <?php
    $mbox = imap_open ("{www.yoursite.com:143}INBOX", "$username", "$password");
    if ( $mbox === false ) {
           exit ("Can't connect: " . imap_last_error() ."\n");
    }
    else
    {
           echo "Login worked!";
           //do stuff
    }
    ?>
    

    更多:http://us.php.net/manual/en/function.imap-last-error.php

    【讨论】:

    • 如果我添加 imap_last_error 我收到以下错误消息:无法打开邮箱 {imap.gmail.com:993/imap/ssl}INBOX: invalid remote specification 关于您的链接,我没有启用两步验证:/
    • 啊,好吧 - 我看到您正在尝试使用 SSL 连接。您能否确认您的 PHP 是否使用这些标志编译?: --with-imap-ssl --with-kerberos --with-openssl 这些是 imap with SSL 所必需的。
    • 我不确定我是否得到了正确的信息,但是使用 phpinfo() 我读到:'--with-openssl=/usr', '--with-imap=/usr/local /src/imap-2001a/' 我唯一能找到“kerberos”的地方是在服务器路径中
    • 好的 - 那么这很可能是问题所在,您可以要求系统管理员使用这些标志编译 PHP,或者您可以尝试在不使用 SSL 的情况下连接到 gmail。
    猜你喜欢
    • 2017-01-21
    • 2014-04-19
    • 2011-10-14
    • 2015-11-05
    • 2023-03-11
    • 2010-09-08
    • 2016-07-07
    • 2017-11-14
    • 2017-11-13
    相关资源
    最近更新 更多