我使用IMAP从我的邮件服务器上读取邮件。
但是,我的收件箱中有大量邮件, 每次我尝试测试时,都需要几分钟才能加载。
我只想要新,未读,前10个电子邮件。
阅读电子邮件:
// open IMAP connection
$dns = "{imap.smtp.domain:993/imap/ssl}INBOX";
$email = "my_mail@domain.com";
$password = "**********";
$mbox = imap_open($dns, $email, $password);
$MC = imap_check($mbox);
if (!$mbox)
die("COULD NOT OPEN MAILBOX!\r\n");
$result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0);
echo "<table>";
$i=1;
foreach ($result as $overview) {
if($i == 10) break;
echo "<tr>"
."<td>".$overview->msgno."</td>"
."<td>".$overview->uid."</td>"
."<td>".$overview->date."</td>"
."<td>".$overview->udate."</td>"
."<td>".$overview->from."</td>"
."<td>".$overview->to."</td>"
."<td>".$overview->size."</td>"
."<td>".$overview->subject."</td>"
."</tr>";
$i++;
}
echo "</table>";
它只返回 10 ,但需要很长时间。
我需要简单快速地阅读电子邮件。
可能吗?
或其他任何解决方案?
答案 0 :(得分:1)
// this will select top 10 emails
$result = imap_fetch_overview($mbox,"1:10",0);
//for recent emals
$mailbox = imap_search($mbox,'RECENT');
// implode gives you id fo the messages
messages = implode(",", $mailbox);
// list of recent emails and you can pass your message ids in string with comma seperated values like(1,2,5,6) in imap_fetch_overview as below
$messages = imap_fetch_overview($mbox,"$messages",0);
// for unseen
$mailbox = imap_search($mbox,'UNSEEN');