PHP Classes

Text and HTML Body

Recommend this page to a friend!

      POP3 e-mail client  >  All threads  >  Text and HTML Body  >  (Un) Subscribe thread alerts  
Subject:Text and HTML Body
Summary:Extract TEXT and HTML Body of email message
Messages:5
Author:Petar
Date:2007-10-01 18:37:29
Update:2008-04-21 08:44:55
 

  1. Text and HTML Body   Reply   Report abuse  
Picture of Petar Petar - 2007-10-01 18:37:29
Hi,

Lots of thanks for excellent classes! May be this is the best collection for email sending and receiving over the net.

I think pop3 and mimeparser need only one think to become priceless - please could you spend some time to write to us a short example how to get both TEXT and HTML body of email using pop3 and mimeparser? Just forget for attachments and anything else.

I (and probably lots of others) just want to set two variables - plain_body and html_body per email. If the mail has been sent in plain text - html_body has to be ''. In any other cases I need the two variables.

Thank you!

  2. Re: Text and HTML Body   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-10-01 19:13:49 - In reply to message 1 from Petar
If you traverse the decoded array returned by the Decode function of the MIME parser class, it is not hard to figure what is the text and HTML parts of the body.

Anyway, it is on my to do list to provide an additional function to simplify decoded message interpretation. Please be patient while I make time to implement it.

  3. Re: Text and HTML Body   Reply   Report abuse  
Picture of TheodoreChen TheodoreChen - 2007-12-25 07:15:22 - In reply to message 2 from Manuel Lemos
I am also looking forward to this function implemented.

I suggest it needs a member function to save attachment to binary file
and wrapped structure to have member variables such as TEXTBODY, HTMLBODY, Array of Attachment info.

Because it is hard to traverse the array to find mail body. the data depth in array are not the same for every mail.

  4. Re: Text and HTML Body   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-01-08 05:35:50 - In reply to message 3 from TheodoreChen
You may try the latest version of the MIME parser class. It has a function named Analyze that can determine the type of message that it was parsed and extract only the relevant parts like the HTML part, text part, attachments, etc..

  5. Re: Text and HTML Body   Reply   Report abuse  
Picture of f5inet f5inet - 2008-04-21 08:44:55 - In reply to message 3 from TheodoreChen
my function for search HTML and TEXT

<?php
$de=$decoded[$message][ExtractedAddresses]['from:'][0][address];
$para=$decoded[$message][ExtractedAddresses]['to:'][0][address];
$asunto=$decoded[$message][Headers]["subject:"];
$fecha=time();

$mensaje=search_for_body($decoded[$message][Parts]);

..............



function search_for_body($parts)
{
$textplain=" ";
$texthtml=" ";
foreach ($parts as $ind=>$part) {
list($temp,$ignore)=explode(";",$part["Headers"]["content-type:"]);
list($tipo,$content)=explode("/",$temp);
if ($tipo."/".$content=="text/plain"){
$textplain=$part["Body"];
}
if ($tipo."/".$content=="text/html"){
$texthtml=$part["Body"];
}
if ($tipo=="multipart"){
$bodies=search_for_body($part["Parts"]);
if (strlen($bodies["plain"])>=strlen($textplain))
$textplain=$bodies["plain"];
if (strlen($bodies["html"])>=strlen($texthtml))
$texthtml=$bodies["html"];
}
}
return array("plain"=>$textplain,"html"=>$texthtml);
}

?>