PHP Classes

Extract TEXT and HTML body parts

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Extract TEXT and HTML body parts  >  (Un) Subscribe thread alerts  
Subject:Extract TEXT and HTML body parts
Summary:Simple function to extract both TEXT and HTML body parts
Messages:2
Author:Petar
Date:2007-10-03 05:49:40
Update:2008-06-26 20:45:28
 

  1. Extract TEXT and HTML body parts   Reply   Report abuse  
Picture of Petar Petar - 2007-10-03 05:49:40
Hi,

This is my suggestion how to extract TEXT and HTML body parts from any kind of emails:

function msgbody($msg, $type = 'text/plain') {
if (is_array($msg)) {
if (array_key_exists('Body', $msg)) {
$tmp = explode(';', $msg['Headers']['content-type:']);
if ($type == trim($tmp[0])) return $msg['Body'];
}
if ((array_key_exists('Parts', $msg)) && (is_array($msg['Parts']))) {
foreach ($msg['Parts'] as $val) {
$res = msgbody($val, $type);
if ($res) return $res;
}
}
}
}

************

How to use it?

$pop3->Open();
$pop3->Login(...));
$pop3->OpenMessage(...);
$pop3->GetMessage(...);

$mime->Decode($parameters, $decoded);

I prefer $mime->mbox = 0; So $decoded = $decoded[0];

$text = msgbody($decoded, 'text/plain');
$html = msgbody($msg, 'text/html');

Any feedback appreciate.

  2. Re: Extract TEXT and HTML body parts   Reply   Report abuse  
Picture of Jeff Jeff - 2008-06-26 20:45:28 - In reply to message 1 from Petar
I am new to this, how can i used your MIME E-mail message parser in Outlook 2007 or do i have to used it on my IP Server and how do i run it.