0

对了,先生们,我整天都在看这个文学,现在我很绝望!这是情况。我正在使用免费的虚拟主机,每当我尝试使用 imap_open 时,都会出现此消息:致命错误:调用未定义的函数 imap_open()。我 obiosly 没有任何访问服务器设置的权限,并且似乎 php 没有安装 imap 模块,即使我直接联系了我的提供商(web000):你支持 imap 功能吗?他回答是的。我确实给他发了一封带有错误消息的电子邮件,问他这怎么可能。还没有他的消息。无论如何,假设 imap 函数未定义,我是否可以访问我的 gmail 内容,有没有我可以下载的库来获得这个功能?谢谢你们的时间。

4

1 回答 1

3

您可以使用Zend_Mail读取 imap 邮箱而无需 imap 扩展,因为它是 IMAP 协议的纯 php 实现(它使用套接字连接到邮件服务器)。

在您的主机上使用 Zend Framework 没有特殊要求。只需下载软件包,解压缩并上传到您的主机上。我建议您使用最低版本,可以运行以下代码。

为了连接到 Gmail 帐户,您可以从此代码开始,它将连接到您的帐户,获取存储在服务器上的第一条消息并输出其主题,然后您可以展开它。

<?
// Ensure Zend folder is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    '/home/tachyon/public_html/zend/library/',
     get_include_path(),
)));

// require the ZF autoloader file if you have it in your include path
require_once 'Zend/Loader/Autoloader.php';
// if ZF is not in your path you can specify the full path
// otherwise if it's in a subdir (most likely if you're on a web hosting)
// you can do something like this
//require_once dirname(__FILE__) . '/Zend/Loader/AutoLoader.php';

// laod the autoloader so you don't need to require any ZF file
Zend_Loader_Autoloader::getInstance();

// connecting with Imap to gmail
$mail = new Zend_Mail_Storage_Imap(
    array(
        'host'     => 'imap.gmail.com',
        'port'     => '993',
        'ssl'      => true,
        'user'     => 'user@gmail.com',
        'password' => 'secret',
    )
);

// get the message object
$message = $mail->getMessage(1);
// output subject of message
echo $message->subject . "\n";
// dump message headers
Zend_Debug::dump($message->getHeaders());

我用我的 Gmail 帐户亲自测试了这个,所以它是有效的代码。

于 2011-07-26T22:15:49.430 回答