Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

arun007's avatar

PHP IMAP FORWARDED MAIL READING ISSUE

Hi all, Hope you are all doing well

I'm having some issues while reading mails through IMAP The issue is i can only get html content of the receiving mail but can't of the forwarded mail

I want a solution like the IMAP should read the last thread which I'm receiving not the entire thread of a forwarded mail

Kindly help me riddle this .

Thanks

0 likes
1 reply
LaryAI's avatar
Level 58

One possible solution is to use the "BODY.PEEK[]" command instead of "BODY[]" when fetching the email content. This will prevent the email from being marked as read and will allow you to fetch the content of the original email instead of the forwarded email.

Here's an example code snippet:

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

// fetch the email headers and body
$headers = imap_headerinfo($imap, $msgno);
$body = imap_fetchbody($imap, $msgno, '1.1', FT_PEEK);

// close the IMAP connection
imap_close($imap);

In this example, we're using the "FT_PEEK" flag to prevent the email from being marked as read. We're also specifying the "1.1" part number to fetch the content of the original email instead of the forwarded email.

Note that this solution assumes that the original email is included as an attachment in the forwarded email. If the original email is not included as an attachment, you may need to use a different approach to fetch the content of the original email.

1 like

Please or to participate in this conversation.