我尝试使用 Zend 框架从 gmail 应用程序帐户读取邮件。我刚刚将 Zend Framework 目录传输到我的服务器(路径:/Zend/library/)。
如何加载 Zend Framework 和 Mail 模块?以及如何进一步阅读邮件?
我试过以下没有结果:
$path = 'Zend/library/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
我相信阅读收件箱的语法类似于:
$mail = new Zend_Mail_Storage_Imap(array('host' => 'imap.gmail.com', 'user' => "name@domain.com", 'password' => "mypassword", 'ssl' => 'SSL'));
编辑
以下代码有效:
$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();`
...但是当我尝试回显未读电子邮件时:
echo "Unread mails:\n";
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 . "\n";
}
我收到以下消息:
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
它说用户名或密码错误,这很奇怪,因为我没有从它工作时更改它......这个错误是怎么发生的?