Exchange-Web-Services-for-PHP
Exchange-Web-Services-for-PHP copied to clipboard
Undefined property: stdClass::$ToRecipients
Thanks for this repo, it's great !!
Today I started to use this lib and have the following error:
PHP Notice: Undefined property: stdClass::$ToRecipients in Exchange-Web-Services-for-PHP/lib/ExchangeClient.php on line 257
Reviewing I found this code block:
if(!is_array($messageobj->ToRecipients->Mailbox)) {
$messageobj->ToRecipients->Mailbox = array($messageobj->ToRecipients->Mailbox);
}
I see this object is referred in $messageobj in the line 241 https://github.com/rileydutton/Exchange-Web-Services-for-PHP/blob/697cc2dcbf4ee1bbe1744adfabd06249125588d0/lib/ExchangeClient.php#L241
When I get all keys, I get this:
MimeContent
ItemId
Subject
Sensitivity
Body
Attachments
Size
DateTimeSent
DateTimeCreated
ResponseObjects
HasAttachments
IsReadReceiptRequested
From
IsRead
I suppouse my Exchange Server not send some propertyes like ToRecipients, fot this reason I suggest check is ToRecipients is set before process it like this:
if (isset($messageobj->ToRecipients)) {
if(!is_array($messageobj->ToRecipients->Mailbox)) {
$messageobj->ToRecipients->Mailbox = array($messageobj->ToRecipients->Mailbox);
}
foreach($messageobj->ToRecipients->Mailbox as $mailbox) {
$newmessage->to_recipients[] = $mailbox;
}
}
Instead
if(!is_array($messageobj->ToRecipients->Mailbox)) {
$messageobj->ToRecipients->Mailbox = array($messageobj->ToRecipients->Mailbox);
}
foreach($messageobj->ToRecipients->Mailbox as $mailbox) {
$newmessage->to_recipients[] = $mailbox;
}