imap_delete

Description

Marks messages listed in msg_number for deletion.
Messages marked for deletion will stay in the mailbox until either
imap_expunge() is called or
imap_close() is called with the optional parameter
CL_EXPUNGE.

Notes

Note:

IMAP mailboxes may not have their message flags saved between connections,
so imap_expunge() should be called during the same
connection in order to guarantee that messages marked for deletion will
actually be purged.

User Contributed Notes 10 notes

I couldn't get imap_delete to work when I used it with pop3. Instead i wrote:<?phpfunction pop3_dele($connection,$message){$status = imap_setflag_full($connection, '1:'.$message, '\\Deleted');imap_expunge($connection); return $status;

This function seems not to work on "[Gmail]/All Mail" mailbox. This is because Gmails keeps only one copy of the message and mailboxes are no more than labels. Deleting a message from a mailbox only removes that label (except for "All Mail" mailbox).To delete from "All Mail" you have to use imap_mail_move() function and move the message to "[Gmail]/Trash" mailbox.

Note: Names of mailboxes in Gmail depends on the language you're using. E.g.: in Spanish "All Mail" is "Todos" and "Trash" is "Papelera".

Just so anyone using this function is aware: if you mark an email to be deleted from a mailbox, that flag does not persist. You need to call imap_expunge() or use the CL_EXPUNGE option with imap_close() to remove the marked email in the same PHP script you marked it in.