How can you extract the "reply_to" address from an email using PHP's imap functions?

To extract the "reply_to" address from an email using PHP's imap functions, you can use the imap_headerinfo() function to get the email headers, and then access the "reply_to" field from the returned object.

$mailbox = imap_open("{your_mail_server:993/imap/ssl}INBOX", "username", "password");
$emails = imap_search($mailbox, 'ALL');

foreach ($emails as $email_number) {
    $header = imap_headerinfo($mailbox, $email_number);
    $reply_to = $header->reply_toaddress;
    
    echo "Reply To: " . $reply_to . "\n";
}

imap_close($mailbox);