php - 如何在 php 中读取 .msg 文件

标签 php msg

我想用PHP语言阅读Outlook .msg邮件,但我不知道如何使用简单的文件读取功能来阅读。

我在我的 Linux 系统中启用了 Mailparse 扩展,通过使用它我可以正确读取 .eml 文件,但不能正确读取 .msg

你能指出我需要使用的正确代码或库吗?

提前致谢

最佳答案

https://github.com/hfig/MAPI会做的。

        require 'autoload.php';


        $newfn= "outlook.msg";
        // message parsing and file IO are kept separate
        $messageFactory = new Hfig\MAPI\MapiMessageFactory();
        $documentFactory = new Hfig\MAPI\OLE\Pear\DocumentFactory();

        $ole = $documentFactory->createFromFile($newfn);
        $message = $messageFactory->parseMessage($ole);

        // raw properties are available from the "properties" member
        echo $message->properties['subject'], "\n";

        // some properties have helper methods
        echo $message->getSender(), "\n";
        echo $message->getBody(), "\n";

        // recipients and attachments are composed objects
        foreach ($message->getRecipients() as $recipient) {
            // eg "To: John Smith <john.smith@example.com>
            echo sprintf('%s: %s', $recipient->getType(), (string)$recipient), "\n";
        }
        exit;

关于php - 如何在 php 中读取 .msg 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41736274/

相关文章:

php - 使用数组设置变量名

c# - 在 C# 中将 MSG 电子邮件转换为 PDF 文件

javascript - 选择多种表单中的表单数据

php - 使用公共(public)列检索所有登录的 session 数据

php - 使用 PHP 和 Mysql 进行记录锁定

c++ - 如何在 Objective-C 或 C++ 中打开 ".msg"(Microsoft Outlook 消息)文件

Python电子邮件,如何删除/刷新消息中的 'To'字段

powershell - 使用Powershell重命名.msg文件

java - 显示来自 MSG 文件的邮件

php foreach 循环