duanping5306 2012-04-12 09:18
浏览 69

使用Zend Framework读取gmail

Im trying to read mails from a gmail apps account by using Zend Framework. I've just transfered the Zend Framework dir to my server (path: /Zend/library/).

How do I load the Zend Framework and the Mail module? And how do I further read the mail?

I've tried the following with no results:

$path = 'Zend/library/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

I believe the syntax for reading the inbox is something like:

$mail = new Zend_Mail_Storage_Imap(array('host' => 'imap.gmail.com', 'user' => "name@domain.com", 'password' => "mypassword", 'ssl' => 'SSL'));

EDIT

The following code works:

$path = 'Zend/library/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

$mail = new Zend_Mail_Storage_Imap(array('host'     => 'imap.gmail.com',
                                         'user'     => 'mail@domain.com',
                                         'password' => 'password',
                                         'ssl'      => 'SSL'));
echo $mail->countMessages();`

... but when i try to echo unread emails:

echo "Unread mails:
";
foreach ($mail as $message) {
    if ($message->hasFlag(Zend_Mail_Storage::FLAG_SEEN)) {
        continue;
    }
    // mark recent/new mails
    if ($message->hasFlag(Zend_Mail_Storage::FLAG_RECENT)) {
        echo '! ';
    } else {
        echo '  ';
    }
    echo $message->subject . "
";
}

I get the following message:

Fatal error: Uncaught exception 'Zend_Mail_Storage_Exception' with message 'cannot login, user or password wrong' in /var/www/zvinx.dk/test/Zend/library/Zend/Mail/Storage/Imap.php:279 Stack trace: #0 /var/www/zvinx.dk/test/gmail.php(11): Zend_Mail_Storage_Imap->__construct(Array) #1 {main} thrown in /var/www/zvinx.dk/test/Zend/library/Zend/Mail/Storage/Imap.php on line 279

It says the username or password is wrong, which is weird cause I didnt change it from when it was working... How come this error occur?

  • 写回答

5条回答 默认 最新

  • dtg78700 2012-04-12 09:21
    关注

    You really don't think that you can start using Zend Framework without reading/learning about the basics of the framework? At least take a look at the quickstart on how to use the framework with the autoloading features and then dive into the Zend_Mail documentation, more specifically the part that says "Reading Mail Messages"

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP