PHP Exchange Web Services - get message body

人走茶凉 提交于 2019-12-13 19:40:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!