dtj4307 2016-04-29 08:50
浏览 48
已采纳

在php imap中从bluemix访问gmail

I am trying to get mails from gmail account with php imap in bluemix application. I believe it is a bluemix config issue.

I have enabled imap in the gmail acount.

In bluemix I added a file .user.ini and I wrote : extension=php_imap.dll

The php code is:

<?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...  */

    ?>

When I run this code I get the first debug message and that's all. no error or other debug.

I might guess that something with the imap.dll setting is wrong.

Can I have advice on this? :)

  • 写回答

1条回答 默认 最新

  • doukun8944 2016-04-29 21:18
    关注

    In the application root directory create the following directory and file if not present:

    .bp-config/options.json
    

    The options.json file should have the following content:

    {
       "PHP_EXTENSIONS": ["imap"]
    }
    

    Push your application again using:

    cf push
    

    Make sure you have IMAP enabled in your Google account and also turn on access for less secure apps per link below:

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

    DISCLAIMER: Google does not recommend to turn on access for less secure apps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划