PHP Exchange Web Services - get message body

I am using PHP EWS library and took this example to get a list of messages which works great.

It looks at details like sender, recipient, subject, time, etc. I've tried looking through the entire library, but I can't seem to work out how to pull the message body and attachments.

Any ideas?

+1


source to share


1 answer


This is well documented on the PHP EWS wiki, here: https://github.com/jamesiarmes/php-ews/wiki/Email-:-Retrieve-All-Email-Attachments

Edit: Use the whole example linked above to get the email attachments and only part of it to get the message:



$message_id = ''; // Id of the email message

$ews = new ExchangeWebServices($host,  $user, $password);

$request = new EWSType_GetItemType();

$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;

$request->ItemIds = new EWSType_NonEmptyArrayOfBaseItemIdsType();
$request->ItemIds->ItemId = new EWSType_ItemIdType();
$request->ItemIds->ItemId->Id = $message_id; 

$response = $ews->GetItem($request);

if( $response->ResponseMessages->GetItemResponseMessage->ResponseCode == 'NoError' &&
    $response->ResponseMessages->GetItemResponseMessage->ResponseClass == 'Success' ) {

    $message = $response->ResponseMessages->GetItemResponseMessage->Items->Message;
}

      

At this point, you have $message

. To access the body $message->body

is an object with bodyType etc. - to actually read the content of the message content use$message->body->_

+5


source







All Articles