0
votes

I'll try to forward a mail with php-ews, but can't get it to work.

I have read the documentation for XML EWS

https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-respond-to-email-messages-by-using-ews-in-exchange

but I'll guess I've missed something.

 $request = new CreateItemType();
 $request->MessageDisposition = MessageDispositionType::SEND_AND_SAVE_COPY;
 $request->Items = new NonEmptyArrayOfAllItemsType();
 $request->Items->ForwardedItem = new ForwardItemType();
 $request->Items->ForwardedItem->ToRecipients = new MessageType();
 $request->Items->ForwardedItem->ToRecipients->Mailbox = new EmailAddressType();
 $request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxName = 'Foo Bar';
 $request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxAddress = '[email protected]';
 $request->Items->ForwardedItem->ReferenceItemId = new ItemIdType();
 $request->Items->ForwardedItem->ReferenceItemId->Id = 'AAMk.....AAA=';
 $request->Items->ForwardedItem->ReferenceItemId->ChangeKey = 'CQAA.....GOP';
 $request->Items->ForwardedItem->NewBodyContent = new BodyContentType();
 $request->Items->ForwardedItem->NewBodyContent->Value = 'Test';
 $request->Items->ForwardedItem->NewBodyContent->BodyType = BodyTypeType::HTML;

The error message I'll get is:

Fatal error: Uncaught SoapFault exception: [a:ErrorInvalidRequest] Id must be non-empty.

1

1 Answers

0
votes

This doesn't look right

 $request->Items->ForwardedItem->ToRecipients = new MessageType();
 $request->Items->ForwardedItem->ToRecipients->Mailbox = new EmailAddressType();
 $request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxName = 'Foo Bar';
 $request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxAddress = '[email protected]';

ToRecipients should be an array of recipient types so i think it should be

$request->Items->ForwardedItem->ToRecipients = new ArrayOfRecipientsType();
$recipient = new EmailAddressType();
$recipient->Name = 'Homer Simpson';
$recipient->EmailAddress = '[email protected]';
$request->Items->ForwardedItem->ToRecipients->Mailbox[] = $recipient;