我有一个第三方程序,该程序基本上允许用户发送电子邮件,然后将其显示在系统中.但是问题在于它正在生成这样的输出:我只想获取这些数据并将其格式化为可呈现的格式.我想避免使用REGEX.是否有任何其他选项或标准方式可以更恰当地显示以下内容.基本上,我将下面的所有内容都关联为$text,然后调用各种函数clean($text).
> 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
Testtest
--B_3331365494_4098727--
解决方法:
PEAR::Mail_mimeDecode是解码MIME消息的绝佳类.安装后,您可以按以下方式使用它:
$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,regex,email
来源: https://codeday.me/bug/20191012/1896688.html