Getting Single Mail via garethp/php-ews

Viewed 590

Code:

$api = MailAPI::withUsernameAndPassword($server, $username, $password);
$folder1 = $api->getFolderByDisplayName('PubFolder', DistinguishedFolderIdNameType::PUBLICFOLDERSROOT);
$subFolder1 = $api->getFolderByDisplayName($data['mailfolder'], $folder1->getFolderId());
$api->setFolderId($subFolder1->getFolderId());

$mail = $api->getMailItems($data['id']);

Error: Exception 'Error' with message 'Call to a member function toXmlObject() on string'

Description: I'd like to get a single Mail item via the id, however since i need to call it from a different page and load the content via JS i am unable to send the MailID object which i can get by using $singleMail->getItemId() inside a foreach. So i have to use $singleMail->getItemId()->getId() which yields the ID as a string, however when trying to get the mail via ID I get the above error.

So, how should i proceed? Requesting all Mails and looping till i find the ID again is not an option.

Am I using getMailItems() wrongly? If so please correct me.

Can i Create the correct ID-Object somehow?

Or is there an alternative way to query a Single Mail via the ID-String? Optionally I would be looking for the manuel building of the Query.

1 Answers
Related