How can the imap_expunge() function impact the deletion of emails in a PHP script?

The imap_expunge() function in PHP is used to permanently delete emails marked for deletion in an IMAP mailbox. Without calling imap_expunge(), emails marked for deletion will not be removed from the mailbox. To ensure that emails are properly deleted, it is important to use imap_expunge() after marking emails for deletion using imap_delete().

// Connect to the IMAP server
$mailbox = imap_open('{mail.example.com:993/imap/ssl}INBOX', 'username', 'password');

// Mark email with UID 123 for deletion
imap_delete($mailbox, 123);

// Permanently delete emails marked for deletion
imap_expunge($mailbox);

// Close the connection to the IMAP server
imap_close($mailbox);