【问题标题】:Read MIME data using PHP使用 PHP 读取 MIME 数据
【发布时间】:2009-07-26 13:04:14
【问题描述】:

我有一个第三方程序,它基本上允许用户发送电子邮件,然后将其显示在系统中。但问题是它正在生成这样的输出:我只想获取这些数据并将其格式化为可呈现的形式。我想避免使用正则表达式。是否有任何选项或标准方式以更美观的方式显示以下内容。基本上我会将下面的所有内容都关联为 $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

<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--

【问题讨论】:

    标签: php regex email


    【解决方案1】:

    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 文件?
    • 使用“下载”>“手动安装”同时下载 Mail_MimeMail_mimeDecode。提取两者,更正包含,你应该很高兴!
    猜你喜欢
    • 2011-08-17
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    • 2012-05-28
    • 1970-01-01
    相关资源
    最近更新 更多