2016-04-29 113 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

相关问题