0

I use https://github.com/jamesiarmes/php-ews library to access my exchange account.

If I used correct credentials to create a ExchangeWebServices object, I get accurate response.

$ews = new ExchangeWebServices("outlook.office365.com", "tes@abc.com", "test123");

$request = new EWSType_FindItemType();

$response = $ews->FindItem($request);

But If the credentials are wrong it breaks the site by throwing an exception as

EWS_Exception: SOAP client returned status of 401 in ExchangeWebServices->processResponse() 

Is there any way to get the response as "failed" or some boolean value instead of the error message?

Pravin Ajaaz
  • 107
  • 6

1 Answers1

2

There's no way to get the response as a boolean, but you can do something like

$ews = new ExchangeWebServices("outlook.office365.com", "tes@abc.com", "test123");

$request = new EWSType_FindItemType();

try {
    $response = $ews->FindItem($request);
} catch (\Exception $e) {
    //The response failed.
}

Also, that version of php-ews is out of date and unmaintained. Might I suggest you try https://github.com/Garethp/php-ews

Gareth Parker
  • 5,012
  • 2
  • 18
  • 42
  • Thanks parker :) I would use the library you suggested. Is there lots of difference Btwn the one I use and this? – Pravin Ajaaz Aug 27 '15 at 09:04
  • 1
    A fair bit of difference, yeah. The general structure is the same, but there are bits that are made easier to use, but if you want you can just use it in the same way as the one you're using at the moment. You can still do $ews = new ExchangeWebServices($server, $username, $password); $ews->FindItem(); though. – Gareth Parker Aug 27 '15 at 09:09