我使用我的用户名和密码连接到服务器。它使用 2 的资源 id 连接。它正确显示状态,列出收件箱中未读电子邮件的数量、最近的邮件等。但是当涉及 imap_num_msg() 函数时,我传入了正确的参数,但它返回 0 .我做错了什么让它返回0?
<?php
$mbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", "xxxxx", "xxxxxx", OP_HALFOPEN)
or die("can't connect: " . imap_last_error());
$list = imap_list($mbox, "{imap.gmail.com:993/imap/ssl}INBOX", "*");
if (is_array($list)) {
foreach ($list as $val) {
echo imap_utf7_decode($val) . "\n";
}
} else {
echo "imap_list failed: " . imap_last_error() . "\n";
}
$status = imap_status($mbox, "{imap.gmail.com:993/imap/ssl}INBOX", SA_ALL);
if ($status) {
echo "Messages: " . $status->messages . "<br />\n";
echo "Recent: " . $status->recent . "<br />\n";
echo "Unseen: " . $status->unseen . "<br />\n";
echo "UIDnext: " . $status->uidnext . "<br />\n";
echo "UIDvalidity:" . $status->uidvalidity . "<br />\n";
} else {
echo "imap_status failed: " . imap_last_error() . "\n";
}
$numMessages = imap_num_msg($mbox);
if ($numMessages) {
echo $numMessages;
} else {
echo "imap_status failed: " . imap_last_error() . "\n";
}
imap_close($mbox);
?>