How do I parse HTML email using PHP IMAP?
Asked Answered
B

1

5

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

Brogan answered 15/2, 2011 at 21:59 Comment(2)
What should be the end result? Do you want to re-display it as an HTML page or are extracting certain parts for a database? More info please.Worcester
@Anriëtte, thank you for your comment. I believe my last line say it all: I want to extract the information in HTML so I can parse it later.Brogan
B
12

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).

Bollard answered 15/2, 2011 at 22:17 Comment(1)
Nice, Learn something new everyday, +1Hagler

© 2022 - 2024 — McMap. All rights reserved.