
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.