The error: Unknown: Mailbox is empty (errflg=1) in Unknown on line 0
appears when:
1) use imap_open to connect
2) then use imap_search ALL to retrieve emails
but there are no messages available. To avoid this error, check first the number of messages in a mailbox using imap_status. Only if there are messages available then you can use the imap_search.