douchongbc72264 2012-06-01 07:34
浏览 114
已采纳

PHP Exchange Web服务 - 获取消息正文

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条回答 默认 最新

  • doujiao3016 2012-06-04 13:35
    关注

    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->_

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?