2016-04-29 65 views
0

信息PHP-EWS:致命錯誤:未捕獲的SOAPFault異常:[客戶]班「EWS_Exception」

我一直在運行此代碼就像是一年,一切工作正常,直到昨天。看到下面的錯誤信息。該代碼只提取收件箱中未讀電子郵件的數量。在增加數量的同時,它還會在運行代碼的客戶端上播放聲音。我的Exchange服務器正在運行Exchange Server 2013 CU12但它一直與ExchangeWebServices :: VERSION_2010(請參閱代碼bolow)一起使用。

錯誤消息

致命錯誤:未捕獲的SOAPFault異常:[客戶]類 'EWS_Exception' 在/var/www/html/php-ews/NTLMSoapClient.php:87堆棧跟蹤未找到:#0 /var/www/html/php-ews/NTLMSoapClient.php(87):NTLMSoapClient :: __ doRequest()#1 [內部函數]:NTLMSoapClient-> __doRequest('https://mail.se ...',' ',1,0)#2 /var/www/html/php-ews/ExchangeWebServices.php(552):SoapClient - > __ call('FindItem',Array)#3/var/www/html /php-ews/ExchangeWebServices.php(552):NTLMSoapClient_Exchange-> FindItem(Object(EWSType_FindItemType))#4 /var/www/html/mail.php(104):ExchangeWebServices-> FindItem(Object(EWSType_FindItemType))#5 {main}拋出/ var/www/html/php-ew S/NTLMSoapClient.php上線是基於一個87

我的代碼在這裏找到:http://litphp.info/want_to_print_unread_mail_body_and_subject_using_ews_from_exchange_server_in_php

我的代碼

function __autoload($class_name) 
{ 
    // Start from the base path and determine the location from the class name, 
    $base_path = 'php-ews'; 
    $include_file = $base_path . '/' . str_replace('_', '/', $class_name) . '.php'; 

    return (file_exists($include_file) ? require_once $include_file : false); 
} 

$ews = new ExchangeWebServices("mail.server.path.com", $mailuser, $mailpass, ExchangeWebServices::VERSION_2010); 

$request = new EWSType_FindItemType(); 
$itemProperties = new EWSType_ItemResponseShapeType(); 
$itemProperties->BaseShape = EWSType_DefaultShapeNamesType::ID_ONLY; 
$itemProperties->BodyType = EWSType_BodyTypeResponseType::BEST; 
$request->ItemShape = $itemProperties; 

$fieldType = new EWSType_PathToUnindexedFieldType(); 
$fieldType->FieldURI = 'message:IsRead'; 

$constant = new EWSType_FieldURIOrConstantType(); 
$constant->Constant = new EWSType_ConstantValueType(); 
$constant->Constant->Value = "0"; 

$IsEqTo = new EWSType_IsEqualToType(); 
$IsEqTo->FieldURIOrConstant = $constant; 
$IsEqTo->Path = $fieldType; 

$request->Restriction = new EWSType_RestrictionType(); 
$request->Restriction->IsEqualTo = new EWSType_IsEqualToType(); 
$request->Restriction->IsEqualTo->FieldURI = $fieldType; 
$request->Restriction->IsEqualTo->FieldURIOrConstant = $constant; 

$request->IndexedPageItemView = new EWSType_IndexedPageViewType(); 
$request->IndexedPageItemView->BasePoint = 'Beginning'; 
$request->IndexedPageItemView->Offset = 0; 

$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType(); 
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType(); 
$request->ParentFolderIds->DistinguishedFolderId->Mailbox = new StdClass; 
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = '[email protected]'; 
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX; 

$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW; 

$result = new EWSType_FindItemResponseMessageType(); 
$result = $ews->FindItem($request); 

if ($result->ResponseMessages->FindItemResponseMessage->ResponseCode == 'NoError' && $result->ResponseMessages->FindItemResponseMessage->ResponseClass == 'Success'){ 

    // Need this variable to check for the new value. 
    $count_new = $result->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView; 

    // Play sound if value has increased. 
    if($_SESSION['count_previous'] < $count_new) { 
     echo '<script type="text/javascript">play_sound();</script>'; 
    } 

    // Saving the value for later usage. 
    $count = $result->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView; 

    // Saving the current count to a session. Need it to compair with the new value ($count_new). 
    $_SESSION['count_previous'] = $count; 

    if($count > 0) { 
     echo '<script type="text/javascript">document.body.style.backgroundColor = "#fc2828";</script>'; 
     echo "<h1>" . $count . "</h1><br>"; 
     echo '<img src="img/mail.png" height="165px">'; 
    } else { 
     echo '<h1 class="paddingH12 test">No mail</h1>'; 
    } 

} 

一段時間,我認爲這可能是代碼停止後因爲服務器是2013 CU12,因此「像」VERSION_2010一樣工作。我嘗試了以下解決方案,但它沒有奏效:https://github.com/jamesiarmes/php-ews/issues/195

有誰知道這個問題可以如何解決?這有點令人沮喪,因爲代碼工作了一年,現在沒有。服務器端沒有任何變化。

在此先感謝。

+2

我會強烈建議

我也就達60秒(否則聲音不工作)後刷新頁面你離開他的圖書館,這是舊的和無人維護的。我建議在http://github.com/garethp/php-ews嘗試我的分支,其中包括一個關於如何輕鬆獲取未讀電子郵件的簡單示例。 –

+0

Aha,非常感謝。我會檢查出來的。 – Treps

回答

0

對不起,這篇文章。它現在正在工作。我不知道問題是什麼。 Exchange服務器或網絡上的負載可能很高。隨意使用此代碼只獲取未讀的電子郵件。

<meta http-equiv="refresh" content="60"> 

JavaScript的聲音(在頭):

<script type="text/javascript"> 
    function play_sound() { 
     var audioElement = document.createElement('audio'); 
     audioElement.setAttribute('src', '/sound/mail.mp3'); 
     audioElement.setAttribute('autoplay', 'autoplay'); 
     audioElement.load(); 
     audioElement.play(); 
    } 
</script> 
+0

該代碼適用於Exchange 2013,2013 CU11和2013 CU12。即使它說2010年;) – Treps

相關問題