使用PHP读取MIME数据 [英] Read MIME data using PHP
问题描述
我有一个第三方程序,基本上允许用户发送电子邮件,然后将其显示在系统中。但问题是它正在生成一个这样的输出:我想把这些数据和格式化为可呈现的东西。我想避免REGEX。是否有任何选项或标准方式以更可呈现的方式显示下面的内容。基本上,我会将以下所有内容与$ text相关联,然后调用一个函数clean($ text)。
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--
推荐答案
PEAR :: Mail_mimeDecode
是一个很好的解码MIME消息的类。一旦安装,您可以这样使用:
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.
这篇关于使用PHP读取MIME数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!