在 php imap 中从 bluemix 访问 gmail

Accesing gmail from bluemix in php imap

我正在尝试在 bluemix 应用程序中使用 php imap 从 gmail 帐户获取邮件。 我认为这是一个 bluemix 配置问题。

我在 gmail 帐户中启用了 imap。

在 bluemix 中我添加了一个文件 .user.ini 并且我写了:extension=php_imap.dll

php代码是:

<?p

    hp
     set_time_limit(60); 
     /* connect to gmail with your credentials */
    $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';

    $username = 'mygmailaccount@gmail.com';  

    $password = 'mypassword';
    /* try to connect */

    print_r('debug: just before accessing gmail');

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

    print_r('debug: i did not die when accesing gmail ');

    /*here is more code but I do not access this...  */

    ?>

当我 运行 这段代码时,我得到了第一条调试消息,仅此而已。没有错误或其他调试。

我可能猜想 imap.dll 设置有问题。

我可以就此提出建议吗? :)

在应用程序根目录中创建以下目录和文件(如果不存在):

.bp-config/options.json

options.json 文件应包含以下内容:

{
   "PHP_EXTENSIONS": ["imap"]
}

使用以下方式再次推送您的应用程序:

cf push

确保在您的 Google 帐户中启用了 IMAP,并根据下面的 link 打开对安全性较低的应用程序的访问权限:

https://support.google.com/accounts/answer/6010255

免责声明:Google不建议为安全性较低的应用程序打开访问权限。