Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I parse HTML email using PHP IMAP?

I'm trying to parse HTML data in an email using PHP's IMAP functions.

When I echo imap_body($Mailbox, 1); by example, the HTMl contained inside seems to be converted into a different encoding (MIME I suspect)

Here is a sample chunk of $body:

<TH=20
      style=3D"PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: =
5px; COLOR: #fff; PADDING-TOP: 5px; BORDER-BOTTOM: #6eafd0 1px solid; =
BACKGROUND-COLOR: #004454"=20
      align=3Dleft>Site</TH>

How do I convert the received the body data into parsable HTML ?

Thank you

like image 729
Cybrix Avatar asked Feb 15 '11 21:02

Cybrix


1 Answers

Yes, looks old MIMEish. Perhaps try $decoded = quoted_printable_decode ( $body );

The "3D" part is a give away: "US-ASCII equal sign (decimal value 61) must be represented by '=3D'". ( wiki on quoted-printable encoding).

like image 145
jpwco Avatar answered Oct 04 '22 22:10

jpwco