问题
I'm using a PHP EWS library, and took this example to get a list of messages, which works perfectly.
It pulls through details such as the sender, receiver, subject, time etc. I tried looking through all the library, but I can't workout how to pull through the message body and attachments.
Any ideas?
回答1:
It is well described in PHP EWS wiki, right here: https://github.com/jamesiarmes/php-ews/wiki/Email-:-Retrieve-All-Email-Attachments
Edit: use whole example linked above to fetch email attachments and just 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 the $message
. To access body use $message->body
- it's an object with bodyType etc - to actually read the message body content use $message->body->_
来源:https://stackoverflow.com/questions/10846245/php-exchange-web-services-get-message-body