我正在使用php imap函数解析来自webmail的消息。我可以一个接一个地获取消息并将它们保存在数据库中。保存后,我想删除收件箱邮件。imap_delete函数在此不起作用。我的代码是这样的:

$connection = pop3_login($host,$port,$user,$pass,$folder="INBOX",$ssl=false);//connect
$stat = pop3_list($connection);//list messages

foreach($stat as $line) {
  //save in db codes...
  imap_delete($connection, $line['msgno']);//flag as delete
}

imap_close($connection, CL_EXPUNGE);

我还测试了-imap_expunge($connection);
但它不起作用。不会删除邮件。请帮我…

最佳答案

你在混合pop和imap。
那是行不通的。你需要打开与imap的连接。请参见以下示例:

<?php

$mbox = imap_open("{imap.example.org}INBOX", "username", "password")
    or die("Can't connect: " . imap_last_error());

$check = imap_mailboxmsginfo($mbox);
echo "Messages before delete: " . $check->Nmsgs . "<br />\n";

imap_delete($mbox, 1);

$check = imap_mailboxmsginfo($mbox);
echo "Messages after  delete: " . $check->Nmsgs . "<br />\n";

imap_expunge($mbox);

$check = imap_mailboxmsginfo($mbox);
echo "Messages after expunge: " . $check->Nmsgs . "<br />\n";

imap_close($mbox);
?>

07-28 09:42