你可以使用imap_search
1和imap_setflag_full
2的组合
$mailbox = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', 'example@gmail.com', 'password');
// This gives an array of message IDs for all messages that are UNSEEN
$unseenMessages = imap_search($mailbox, 'UNSEEN');
// Keep in mind that imap_search returns false, if it doesn't find anything
$unseenCount = !$unseenMessages ? 0 : count($unseenMessages);
echo "$unseenCount New Emails!\n";
if ($unseenMessages) {
// The second parameter of imap_setflag_full function is a comma separated string of message IDs
// It can also be a range eg 1:5, which would be the same as 1,2,3,4,5
imap_setflag_full($mailbox, implode(',', $unseenMessages), '\Seen');
}