【发布时间】:2022-01-05 20:36:09
【问题描述】:
我想用 PHP 语言阅读 Outlook .msg 电子邮件,但我不知道如何用简单的文件读取功能阅读它。
我在我的 Linux 系统中启用了 Mailparse 扩展,通过使用它我可以正确读取 .eml 文件,但不能正确读取 .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;
【讨论】:
你可以使用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();
【讨论】: