【问题标题】:PHP-EWS fails on more than one attachmentPHP-EWS 在多个附件上失败
【发布时间】:2014-11-30 13:33:25
【问题描述】:

我使用James Armes's PHP-EWS library

以下代码适用于单个附件,但适用于多个文件。

<?php
$msgRequest->MessageDisposition = 'SaveOnly';

$msgResponse = $ews->CreateItem($msgRequest);
$msgResponseItems = $msgResponse->ResponseMessages->CreateItemResponseMessage->Items;

// Create attachment(s)
$attachments = array();
$i = 0;
foreach ($message_details['attachment'] as $attachment) {
    $attachments[$i] = new EWSType_FileAttachmentType();
    $attachments[$i]->Content = file_get_contents($attachment['path'] . '/' . $attachment['file']);
    $attachments[$i]->Name = $attachment['file'];
    $i++;
}
//
// Attach files to message
$attRequest = new EWSType_CreateAttachmentType();
$attRequest->ParentItemId = $msgResponseItems->Message->ItemId;
$attRequest->Attachments = new EWSType_NonEmptyArrayOfAttachmentsType();
$attRequest->Attachments->FileAttachment = $attachments;

$attResponse = $ews->CreateAttachment($attRequest);
$attResponseId = $attResponse->ResponseMessages->CreateAttachmentResponseMessage->Attachments->FileAttachment->AttachmentId;

// Save message id from create attachment response
$msgItemId = new EWSType_ItemIdType();
$msgItemId->ChangeKey = $attResponseId->RootItemChangeKey;
$msgItemId->Id = $attResponseId->RootItemId;

// Send and save message
$msgSendRequest = new EWSType_SendItemType();
$msgSendRequest->ItemIds = new EWSType_NonEmptyArrayOfBaseItemIdsType();
$msgSendRequest->ItemIds->ItemId = $msgItemId;
$msgSendRequest->SaveItemToFolder = true;
$msgSendResponse = $ews->SendItem($msgSendRequest);
$response = $msgSendResponse->ResponseMessages->SendItemResponseMessage;
?>

$ews->SendItem() 返回此错误:

未捕获的 SoapFault 异常:[a:ErrorSchemaValidation] 请求 架构验证失败:缺少必需的属性“Id”。

我错过了什么?

【问题讨论】:

    标签: php exchangewebservices php-ews


    【解决方案1】:

    在这里找到答案:

    https://github.com/jamesiarmes/php-ews/issues/132

    如果只有一个附件,Exchange 基本上不会使用数组,因此需要进行额外检查以确定从何处获取 ID。

    if(!is_array($attResponse->ResponseMessages->CreateAttachmentResponseMessage))
        $attResponseId = $attResponse->ResponseMessages->CreateAttachmentResponseMessage->Attachments->FileAttachment->AttachmentId;
    else {
        $attResponseId = $attResponse->ResponseMessages->CreateAttachmentResponseMessage[0]->Attachments->FileAttachment->AttachmentId;
    }
    

    Exchange 对收件人使用相同的结构。我觉得这不一致,但我相信这背后是有原因的。

    我希望有人能从提出这个问题中受益。

    【讨论】:

      猜你喜欢
      • 2019-11-26
      • 2022-10-14
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2016-08-15
      • 2013-03-03
      • 1970-01-01
      相关资源
      最近更新 更多