Actually ... The reason that the emails remained in the Inbox was that when imap_mail_move did this, the identifiers of all the remaining messages were reduced by one, so when the foreach loop moved to the next message, one message remained behind. This message skipping is repeated for each iteration. This is why imap_mail_move seemed to not work.
The solution is to use unique message UIDs instead of potentially duplicate identifiers:
$inbox = imap_open( $host, $user, $pass ); $emails = imap_search( $inbox, 'ALL', SE_UID ); if( $emails ) { foreach( $emails as $email_uid ) { imap_mail_move($inbox, $email_uid, 'processed', CP_UID); } }
source share