PHP Classes

Decoding failes when email starts with UTF-8 byte order mark

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Decoding failes when email starts...  >  (Un) Subscribe thread alerts  
Subject:Decoding failes when email starts...
Summary:Decoding failes when email starts with UTF-8 byte order mark
Messages:2
Author:Klemen
Date:2025-10-26 14:37:03
 

  1. Decoding failes when email starts...   Reply   Report abuse  
Picture of Klemen Klemen - 2025-10-26 14:37:03
Hi,

If the email starts with the UTF-8 byte order mark (BOM; 0xEF, 0xBB, 0xBF) this class does not parse it correctly.

Microsoft 365, for example, when sending an email via POP3, starts the stream with the UTF-8 BOM.

Instead of parsing it, the entire email is detected as "Type: Text" and no headers are processed.

I fixed it temporarily like this:

Find the first instance of:

return($this->SetPHPError('could not read the message file'));

After that code, add:
if(substr($data,0,3)==chr(hexdec('EF')).chr(hexdec('BB')).chr(hexdec('BF'))){
$data = substr($data,3);
}

  2. Re: Decoding failes when email starts...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2025-10-27 20:26:05 - In reply to message 1 from Klemen
Hello Klemen,

Thank you for your contribution.

Can you share a sample EML message that I can use to reproduce the issue and test your changes?