Parse email message insert into mysql database using imap

Hi

I'm working on a script that retrives emails from the server using imap and inserts them in to database.

retrieving and inserting part works fine,
but when it comes to html messages the thing goes creazy

here is the result i get when i view the email from the database online. can someone help with cleaning this email up?

thanks

------------
This is a multi-part message in MIME format.brbr------_NextPart_000_0003_01C65CB9.A09AC300brContent-Type: text/plain;brcharsetus-asciibrContent-Transfer-Encoding: 7bitbrbrHere is the test emailbrbr brbr brbr brbr brbr brbrProfesionally YoursbrbrHarry Hovakbrbr-----------------------------brbrWebmaster Services PHP Mysql Developmentbrbrhttp://www.phpwork.combrbrWebmaster Tutorialsbrbrhttp://www.askwebexperts.combrbrInternet Turnkey Sitesbrbrhttp://www.internetturnkeysites.combrbr brbrbr------_NextPart_000_0003_01C65CB9.A09AC300brContent-Type: text/html;brcharsetus-asciibrContent-Transfer-Encoding: quoted-printablebrbrhtml xmlns:o3Durn:schemas-microsoft-com:office:office brxmlns:w3Durn:schemas-microsoft-com:office:word brxmlns3Dhttp://www.w3.org/TR/REC-html40brbrheadbrMETA HTTP-EQUIV3DContent-Type CONTENT3Dtext/html; brcharset3Dus-asciibrmeta name3DGenerator content3DMicrosoft Word 11 (filtered medium)brstylebr!--br /* Style Definitions */br p.MsoNormal, li.MsoNormal, div.MsoNormalbr{margin:0in;brmargin-bottom:.0001pt;brfont-size:12.0pt;brfont-family:Times New Roman;}bra:link, span.MsoHyperlinkbr{color:blue;brtext-decoration:underline;}bra:visited, span.MsoHyperlinkFollowedbr{color:purple;brtext-decoration:underline;}brspan.EmailStyle17br{mso-style-type:personal-compose;brfont-family:Arial;brcolor:windowtext;}br@page Section1br{size:8.5in 11.0in;brmargin:1.0in 1.25in 1.0in 1.25in;}brdiv.Section1br{page:Section1;}br--br/stylebrbr/headbrbrbody lang3DEN-US link3Dblue vlink3Dpurplebrbrdiv class3DSection1brbrp class3DMsoNormalfont size3D2 face3DArialspan brstyle3D'font-size:10.0pt;brfont-family:Arial'Here is the test emailo:p/o:p/span/font/pbrbrp class3DMsoNormalfont size3D2 face3DArialspan brstyle3D'font-size:10.0pt;brfont-family:Arial'o:pnbsp;/o:p/span/font/pbrbrp class3DMsoNormalfont size3D2 face3DArialspan brstyle3D'font-size:10.0pt;brfont-family:Arial'o:pnbsp;/o:p/span/font/pbrbrp class3DMsoNormalfont size3D3 face3DTimes New Romanspan brstyle3D'font-size:br12.0pt'nbsp;o:p/o:p/span/font/pbrbrp class3DMsoNormalfont size3D3 face3DTimes New Romanspan brstyle3D'font-size:br12.0pt'nbsp;o:p/o:p/span/font/pbrbrp class3DMsoNormalfont size3D3 face3DTimes New Romanspan brstyle3D'font-size:br12.0pt'nbsp;o:p/o:p/span/font/pbrbrp class3DMsoNormalfont size3D2 face3DArialspan brstyle3D'font-size:10.0pt;brfont-family:Arial'Profesionally Yours/span/fonto:p/o:p/pbrbrp class3DMsoNormalfont size3D2 face3DArialspan brstyle3D'font-size:10.0pt;brfont-family:Arial'Harry Hovak/span/fonto:p/o:p/pbrbrp class3DMsoNormalfont size3D2 face3DArialspan brstyle3D'font-size:10.0pt;brfont-family:Arial'-----------------------------/span/fonto:p/o:pbr/pbrbrp class3DMsoNormalstrongbfont size3D2 face3DArialspan brstyle3D'font-size:br10.0pt;font-family:Arial'Webmaster Services amp; PHP amp; Mysql brDevelopment/span/font/b/strongo:p/o:p/pbrbrp class3DMsoNormalfont size3D2 face3DArialspan brstyle3D'font-size:10.0pt;brfont-family:Arial'a brhref3Dhttp://www.phpwork.comhttp://www.phpwork.com/a/span/fontbro:p/o:p/pbrbrp class3DMsoNormalstrongbfont size3D2 face3DArialspan brstyle3D'font-size:br10.0pt;font-family:Arial'Webmaster brTutorials/span/font/b/strongo:p/o:p/pbrbrp class3DMsoNormalfont size3D2 face3DArialspan brstyle3D'font-size:10.0pt;brfont-family:Arial'a brhref3Dhttp://www.askwebexperts.comhttp://www.askwebexperts.com/a/sbrpan/fonto:p/o:p/pbrbrp class3DMsoNormalstrongbfont size3D2 face3DArialspan brstyle3D'font-size:br10.0pt;font-family:Arial'Internet Turnkey brSites/span/font/b/strongo:p/o:p/pbrbrp class3DMsoNormalfont size3D2 face3DArialspan brstyle3D'font-size:10.0pt;brfont-family:Arial'a brhref3Dhttp://www.internetturnkeysites.comhttp://www.internetturnkeysibrtes.com/a/span/fonto:p/o:p/pbrbrp class3DMsoNormalfont size3D3 face3DTimes New Romanspan brstyle3D'font-size:br12.0pt'o:pnbsp;/o:p/span/font/pbrbr/divbrbr/bodybrbr/htmlbrbr------_NextPart_000_0003_01C65CB9.A09AC300--brbr
-----------------------------------
cgibuysAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

blue_hunterTechnical ConsultantCommented:
work out with Pear's package
Mail_Mime
to clean up your email

http://pear.php.net/package/Mail_Mime

*all the instructions on how you can applied this classes is listed in the tar file that you download from the link above.

all the best.
cheers
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eddie ShipmanAll-around developerCommented:
Use this:
htmlspecialchars(quoted_printable_decode(imap_body($mailbox,$index)));

BTW, that is some attrocious looking MSWord HTML.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.