我的主机公司不会在我们的网络服务器上启用IMAP扩展程序,因此我无法使用IMAP功能。我正在尝试使用Zend \ Mail作为替代,但我无法将本机IMAP功能与Zend \ Mail功能的一对一比例映射出来。
我的部分脚本会检查是否存在打开的IMAP流,如果存在,则关闭它然后重新打开它。这是我的PHP脚本使用IMAP函数的方式:
function open($box='INBOX') {
if ($this->mbox)
$this->close();
$args = array($this->srvstr.$this->mailbox_encode($box),
$this->getUsername(), $this->getPassword());
// Disable Kerberos and NTLM authentication if it happens to be
// supported locally or remotely
if (version_compare(PHP_VERSION, '5.3.2', '>='))
$args += array(NULL, 0, array(
'DISABLE_AUTHENTICATOR' => array('GSSAPI', 'NTLM')));
$this->mbox = call_user_func_array('imap_open', $args);
return $this->mbox;
}
function close($flag=CL_EXPUNGE) {
imap_close($this->mbox, $flag);
}
如何使用Zend \ Mail v2.2做同样的事情?
我尝试过使用此代码,但它在状态500中出错,只返回一个空白屏幕:
function open($box='INBOX') {
if ($mail)
$this->close();
$args = array($this->srvstr.$this->mailbox_encode($box),
$this->getUsername(), $this->getPassword());
// Disable Kerberos and NTLM authentication if it happens to be
// supported locally or remotely
if (version_compare(PHP_VERSION, '5.3.2', '>='))
$args += array(NULL, 0, array(
'DISABLE_AUTHENTICATOR' => array('GSSAPI', 'NTLM')));
$this->getProtocol();
$protocol = $this->ht['protocol'];
if ($protocol=="Imap")
$mail = new Zend\Mail\Storage\Imap($args);
else
$mail = new Zend\Mail\Storage\Pop3($args);
return $mail;
}
function close() {
$mail->close();
$mail='';
}
答案 0 :(得分:0)
你的$ args错了。这就是params的写法:
$mail = new Zend_Mail_Storage_Pop3(array('host' => 'localhost',
'user' => 'test',
'password' => 'test'));