Garethp / php-ews

PHP Exchange Web Services
BSD 3-Clause "New" or "Revised" License
112 stars 45 forks source link

Issue with using toRecipients property in EWS restriction #251

Open hmsfdev opened 1 year ago

hmsfdev commented 1 year ago

I am currently working with Exchange Web Services (EWS) in PHP and I have encountered an issue with using the toRecipients property in the restriction. I have successfully used other properties such as From in the restriction and it works fine. However, when I try to use the toRecipients property, I receive the following error message: "An error occurred: The property can not be used with this type of restriction."

Here is an example of the working restriction using the From property

$restriction = [
    'And' => [
        'And' => [
            'IsEqualTo' => [
                'From' => $email_search,
            ]
        ]
    ]
];

However, when I try to use the toRecipients property in the same way, like this:

$restriction = [
    'And' => [
        'And' => [
            'IsEqualTo' => [
                'toRecipients' => $email_search,
            ]
        ]
    ]
];

. I even tried putting $email_search in an array, but I encounter the error: "Array to string conversion"

I have searched for a solution but haven't found any specific information on using the toRecipients property in EWS restrictions. I would greatly appreciate any guidance or insights on how to properly use the toRecipients property in the restriction.

Thank you in advance for your help.

Matt504 commented 1 year ago

I've never used restrictions with EWS, but maybe the error is that you need to use 'ToRecipients' instead of 'toRecipients' as you can see on this documentation :

$restriction = [
    'And' => [
        'And' => [
            'IsEqualTo' => [
                'ToRecipients' => array('X@mail.com', 'Y@mail.com'), //Or your array $email_search
            ]
        ]
    ]
];

Or maybe something like that :

$restriction = [
        'And' => [
            'IsEqualTo' => [
                'ToRecipients' => array('X@mail.com', 'Y@mail.com'), //Or your array $email_search
            ]
        ]
];
hmsfdev commented 1 year ago

I've never used restrictions with EWS, but maybe the error is that you need to use 'ToRecipients' instead of 'toRecipients' as you can see on this documentation :

$restriction = [
    'And' => [
        'And' => [
            'IsEqualTo' => [
                'ToRecipients' => array('X@mail.com', 'Y@mail.com'), //Or your array $email_search
            ]
        ]
    ]
];

Or maybe something like that :

$restriction = [
        'And' => [
            'IsEqualTo' => [
                'ToRecipients' => array('X@mail.com', 'Y@mail.com'), //Or your array $email_search
            ]
        ]
];

Hello

thanks you for helping , but this code give me Array to string conversion..