I want to read Outlook .msg
email with PHP language and I don't know how to read it with simple file read function.
I have enabled Mailparse extension in my Linux system and by using it I can read the .eml
files correctly but not .msg
.
Could you point me to correct code or library I need to use?
Thanks in advance
https://github.com/hfig/MAPI will do it.
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 <[email protected]>
echo sprintf('%s: %s', $recipient->getType(), (string)$recipient), "\n";
}
exit;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With