我相信你已經通過廣泛的搜索,並最終降落在這裏。讓我們面對它,這是不可能的;但是可以爲該功能提供解決方法。
也許你可以利用類似下面的代碼:
$imap_stream = imap_open($mailbox, $username, $password);
$msg_no = 1212; //lets say momentarily
while(imap_fetchheader($imap_stream, $msg_no)){
//do some processing
$msg_no++;
}// loop will continue till there is no more of newer messages
請注意,這可能會導致最長執行時間,所以你可以在一個for循環做迭代的特定數量的工作。
$imap_stream = imap_open($mailbox, $username, $password);
$msg_no = 1212; //lets say
for($i=0;$i<=50;$i++){
if(imap_fetchheader($imap_stream, $msg_no)){
//do some processing
}
$msg_no++;
} // this will go for 50 times
問題是此代碼使用消息序列號,如果消息被刪除或移動,這些消息序列號可能會改變。因此,如果您將$ msg_no存儲爲最後處理的消息,則會刪除5條消息,您將錯過接下來發送的5條消息。如果你只想從最後一次獲得消息,你需要存儲它的UID,然後執行'$ msg_no = imap_msgno($ imap_stream,$ lastUID);' – 2016-07-13 15:01:03
@CodeBaller是的,這似乎更好。同意。 – 2016-07-15 08:21:15