How to read .msg file in php

I want to read Outlook .msgusing the PHP language, and I don't know how to read it using the simple file read function.

I have enabled the Mailparse extension on my Linux system and using it I can read files correctly .eml, but not .msg.

Could you tell me to fix the code or library that I need to use?

Thanks in advance

+4
source share
2 answers

You can analyze usage Aspose_Email_Java_for_PHPDownload here

Example:

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

Display sender name

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

Display object

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

Display body

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

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

0

, built, .MSG.

:

:

require './msgviewer.php';
$msg = new MSGViewer($file); //File being your .MSG file

, :

//From
$msg->From()['name']; //From: Display name
$msg->From()['email']; //From: Email Address

//To -> Returns in Array with Key = Display Name and Value = Email Address
foreach($msg->To() as $k=>$v) { 

        echo $k . ' ' . $v . ', ';

}

//Subject
$msg->Subject(); //Subject: 

//Body
$msg->Body(); //Body of Email

:

require './msgviewer.php';

$fileArr = ['EmailOne.msg', 'EmailTwo.msg', 'EmailThree.msg'];

foreach($fileArr as $k=>$v) {

    checkMSG($v);
    echo '<br>';


}

function checkMSG($file) {

    $msg = new MSGViewer($file);
    echo 'From: ' . $msg->From()['name'] . ' ' . $msg->From()['email'] . '<br>';
    echo 'To: ';
    foreach($msg->To() as $k=>$v) {

        echo $k . ' ' . $v . ', ';

    }
    echo '<br>Subject: ' . $msg->Subject() . '<br>';
    echo 'Body: ' . $msg->Body() . '<br>';

}
-1

Source: https://habr.com/ru/post/1667231/


All Articles