How can the FT_PEEK flag be utilized in the imap_body function to ensure emails are not deleted when fetching them in PHP?

When using the imap_body function in PHP to fetch emails, the FT_PEEK flag can be utilized to ensure that emails are not marked as seen or deleted when they are fetched. By using this flag, the emails will only be read without any changes to their status. This is useful when you want to retrieve email content without affecting the email's status.

$hostname = '{imap.example.com:993/imap/ssl}INBOX';
$username = 'your_email@example.com';
$password = 'your_password';

$mailbox = imap_open($hostname, $username, $password);

if ($mailbox) {
    $email_number = 1;
    $email_body = imap_body($mailbox, $email_number, FT_PEEK);
    
    echo $email_body;

    imap_close($mailbox);
} else {
    echo "Failed to connect to the mailbox.";
}