| Recommend this page to a friend! |
| PHP MIME Email Message Parser | > | All threads | > | Help with using mime_parser.php | > | (Un) Subscribe thread alerts |
| |||||||||||||||
Hello,
I need basic help with using the mime_parser. Using your sample code, I get the following output: MIME message decoding successful. 1 message was found. Message 1: array(4) { ["Headers"]=> array(12) { ["from "]=> string(43) "[email protected] Sun Apr 22 15:23:22 2012" ["received:"]=> array(4) { [0]=> string(236) "from mail-vx0-f176.google.com ([209.85.220.176]:56702) by sl-507-15.slc.westdc.net with esmtps (TLSv1:RC4-SHA:128) (Exim 4.77) (envelope-from ) id 1SM4Fd-003KV4-KR for [email protected]; Sun, 22 Apr 2012 15:23:22 -0600" [1]=> string(112) "by vcbfl17 with SMTP id fl17so11576880vcb.21 for ; Sun, 22 Apr 2012 14:23:20 -0700 (PDT)" [2]=> string(102) "by 10.220.226.68 with SMTP id iv4mr13351147vcb.21.1335129800559; Sun, 22 Apr 2012 14:23:20 -0700 (PDT)" [3]=> string(66) "by 10.220.186.198 with HTTP; Sun, 22 Apr 2012 14:23:20 -0700 (PDT)" } ["dkim-signature:"]=> string(624) "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=QA+d9CyP0W9F371FrgKQ3liBlzOuwYjlLADfwKA8oo0=; b=MPGOkW6rHJszQw942Ueen0E91+h3O6sHl8b4NA1izUcGpHNWAGqgHxTNtiqEQyAlg6 ZC/D2s1bNPfnOh8s8WyN8HaxOT0AQhtcx5dLKLhpt+c+EbnsikMVtmNqnFZSRC52L9iJ 6+Dw+DVTcG8dL6TZHAH3jmfH7vlNcc6XZRg/KMb5aLJFH9k3cHeo9/pNNM3CJWcfxLZh hOIiWKliNuSmTH9fQDQXnLVmWEyRsER7f9tHV5WFrUDqxnHM2ZagHnaP8vFBeJuvqoBq U3L2IqfnWukKj0AbKBBmNpp23aQNIOfyqqxr/MmmJd4kiJCW1opjBw3tUd6hOIFV8hEu dAdQ==" ["mime-version:"]=> string(3) "1.0" ["in-reply-to:"]=> string(32) "<[email protected]>" ["references:"]=> string(32) "<[email protected]>" ["date:"]=> string(31) "Sun, 22 Apr 2012 14:23:20 -0700" ["message-id:"]=> string(68) "" ["subject:"]=> string(45) "Fwd: The 10 Must-Haves for Sales Compensation" ["from:"]=> string(29) "Leon Yen " ["to:"]=> string(15) "[email protected]" ["content-type:"]=> string(60) "multipart/alternative; boundary=14dae9cdc8cb7dcc3304be4b210e" } ["Parts"]=> array(2) { [0]=> array(5) { ["Headers"]=> array(2) { ["content-type:"]=> string(32) "text/plain; charset=windows-1252" ["content-transfer-encoding:"]=> string(16) "quoted-printable" } ["Parts"]=> array(0) { } ["Position"]=> int(1713) ["BodyPart"]=> int(1) ["BodyLength"]=> int(2383) } [1]=> array(5) { ["Headers"]=> array(2) { ["content-type:"]=> string(31) "text/html; charset=windows-1252" ["content-transfer-encoding:"]=> string(16) "quoted-printable" } ["Parts"]=> array(0) { } ["Position"]=> int(4271) ["BodyPart"]=> int(2) ["BodyLength"]=> int(3623) } } ["Position"]=> int(0) ["ExtractedAddresses"]=> array(2) { ["from:"]=> array(1) { [0]=> array(2) { ["address"]=> string(18) "[email protected]" ["name"]=> string(8) "Leon Yen" } } ["to:"]=> array(1) { [0]=> array(1) { ["address"]=> string(15) "[email protected]" } } } } array(9) { ["Type"]=> string(4) "html" ["Description"]=> string(12) "HTML message" ["Encoding"]=> string(12) "windows-1252" ["DataLength"]=> int(3623) ["Alternative"]=> array(1) { [0]=> array(4) { ["Type"]=> string(4) "text" ["Description"]=> string(12) "Text message" ["Encoding"]=> string(12) "windows-1252" ["DataLength"]=> int(2383) } } ["Subject"]=> string(45) "Fwd: The 10 Must-Haves for Sales Compensation" ["Date"]=> string(31) "Sun, 22 Apr 2012 14:23:20 -0700" ["From"]=> array(1) { [0]=> array(2) { ["address"]=> string(18) "[email protected]" ["name"]=> string(8) "Leon Yen" } } ["To"]=> array(1) { [0]=> array(1) { ["address"]=> string(15) "[email protected]" } } } Now, how do I simply display the message body, and to/from addresses from the header? Thanks, Leon
You should look at the results of the Analyze function. That will tell you what kind of message it is (HTML, text, etc..) as well what information the message contains.
With those details you should be able to make decisions on how to display the message. Just beware that HTML messages may have dangerous JavaScript. You should remove that JavaScript to prevent eventual cross-site scripting attacks. The Secure HTML parser package can assist you on doing the necessary HTML and CSS filtering to prevent those security exploits. phpclasses.org/secure-html-filter
Thanks for your quick reply!
So in the above example, how would I print the body of the message? If you could provide a code snippet, that would be fantastic. Cheers, Leon
What I am trying to explain is that it depends on the type of message.
Plain text messages can be displayed in HTML pages with a <pre> tag inside using HtmlSpecialChars return value on the message content. HTML messages can be displayed in HTML pages as is in but it is safer to filter their contents with the secure HTML parser class mentioned above. |
info at phpclasses dot org.
