Alec Smart
Alec Smart

Reputation: 95900

Read MIME data using PHP

I have a third party program which basically allows users to send email and then it displays it in the system. But the problem is that it is generating an output like this: I want to just take this data and format it to something presentable. I would like to avoid REGEX. Are there any options or standard ways of displaying the content below in a more presentable fashion. Basically I will associate everything below as $text and then call a function clean($text) of sorts.

> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--B_3331365494_4098727
Content-type: text/plain;
charset="US-ASCII"
Content-transfer-encoding: 7bit

test

--B_3331365494_4098727
Content-type: text/html;
charset="US-ASCII"
Content-transfer-encoding: quoted-printable

<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>test</SPAN></FONT>
</BODY>
</HTML>


--B_3331365494_4098727--

Upvotes: 2

Views: 1266

Answers (1)

Andrew Moore
Andrew Moore

Reputation: 95344

PEAR::Mail_mimeDecode is a great class to decode MIME messages. Once installed, you can use it as such:

$message = new Mail_mimeDecode($text);

$params['include_bodies'] = true;
$params['decode_bodies']  = true;
$params['decode_headers'] = true;

$messageStruct = $message->decode($params);
//messageStruct is now an array representing the message
// with all the parts properly included.

Upvotes: 4

Related Questions