【问题标题】:how to read .msg file in php如何在 php 中读取 .msg 文件
【发布时间】:2022-01-05 20:36:09
【问题描述】:

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

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

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

提前致谢

【问题讨论】:

    标签: php msg


    【解决方案1】:

    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;
    

    【讨论】:

      【解决方案2】:

      你可以使用Aspose_Email_Java_for_PHP解析下载here

      一些例子

      $mapiMessage=new MapiMessage();
      $outlook_message_file = $mapiMessage->fromFile($dataDir . "Message.msg");
      

      显示发件人姓名

      print "Sender Name : " . $outlook_message_file->getSenderName();
      

      显示主题

      print "Subject : " . $outlook_message_file->getSubject();
      

      显示体

      print "Body : " . $outlook_message_file->getBody();
      

      参考: https://asposeemailjavaphp.codeplex.com/SourceControl/latest#src/aspose/email/ProgrammingOutlook/WorkingWithOutlookMessageFiles/ParseOutlookMessageFile.php

      【讨论】:

      • 感谢您在不使用 java 和 php 的情况下以其他方式回复
      • 对于 Aspose_Email_Java_for_PHP 我需要在我不想要的服务器上安装 java
      • 如何从 msg 文件中获取附件?是否可以使用 Aspose 库?
      猜你喜欢
      • 2015-06-06
      • 2010-09-06
      • 1970-01-01
      • 2013-08-04
      • 2016-08-15
      • 2016-04-03
      • 2014-12-25
      • 2011-09-07
      • 1970-01-01
      相关资源
      最近更新 更多