Forum Moderators: coopster

Message Too Old, No Replies

Display text or HTML emails in a web page

A script or function?

         

physics

4:32 am on Jun 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want to be able to display emails in a web page whether they are text, HTML or both. Does anyone know of a PHP script or function out there that will parse the original email and display it properly? Thanks.

phparion

5:21 am on Jun 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I didn't get your question completely.

If the emails are stored in a table you just need to 'echo' them in the webpage and they should display whatever form they are in.

physics

3:56 pm on Jun 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If they were plain text then yes. However, start with <html> and some have 'parts' and have both text and html.

------=_Part_2070703_13260018.1175820458911
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

...
------=_Part_2070703_13260018.1175820458911
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

...

I'm sure the open source web mail programs have this but I was just wondering if someone knew of a snippet or PEAR module or something like that.

henry0

5:13 pm on Jun 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the emails are saved (as file with any extension txt, html etc...) somewhere on your server

You may use file_get_contents() [us2.php.net]

barns101

6:28 pm on Jun 4, 2007 (gmt 0)

10+ Year Member



I think he's enquiring more as to how the relevant text / HTML can be isolated from the other information (e.g. headers) rather than how to actually read whole lot. :)

physics

7:50 pm on Jun 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have the email body, sans headers, in a database. The problem is displaying them properly. View raw source on a few emails that have html and images and you'll see my problem...

coopster

10:08 pm on Jun 6, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would grab an open source distro like squirrelmail [sourceforge.net] and see if they have some kind of regular expression or something to handle the parsing. If not, you could build your own.

I'm not sure if the IMAP [php.net] functions would be helpful?

physics

6:03 pm on Jun 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the ideas coopster. Searching for mail on the php.net site I found this:

[us.php.net...]

Available at PECL:

[pecl.php.net...]

Gonna give that a shot.