Skip to content

Undefined property: stdClass::$ToRecipients #33

@alejosv

Description

@alejosv

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

$messageobj = $response->ResponseMessages->GetItemResponseMessage->Items->Message;

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions