如何在 PHP 中通过 IMAP 只读有限的电子邮件?
How to Read Only limited E-Mails by IMAP in PHP?
我使用 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>";
它returns只有10,但它需要很长时间。
我需要简单快速地阅读电子邮件。
可能吗?
或任何其他解决方案?
// 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');
我使用 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>";
它returns只有10,但它需要很长时间。
我需要简单快速地阅读电子邮件。
可能吗?
或任何其他解决方案?
// 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');