php - want to take value in a variable from output of EWS mail -
i taking unread mail using ews exchange server. below output.
stdclass object ( [responsemessages] => stdclass object ( [finditemresponsemessage] => stdclass object ( [responsecode] => noerror [responseclass] => success [rootfolder] => stdclass object ( [items] => stdclass object ( [message] => stdclass object ( [itemid] => stdclass object ( [id] => aamkadllywvjyje3lwmznwitndczyy05yzlllwezmzm2ywuzndy3nqbgaaaaaaa3rnrc1+nerydpkpmlrf8obwdmmobtcfhpsqyuvnmidlrxaaaafjg7aadmmobtcfhpsqyuvnmidlrxaad0o9sfaaa= [changekey] => cqaaabyaaadmmobtcfhpsqyuvnmidlrxaad0o+gx ) [subject] => cr-1167-approved [sensitivity] => normal [size] => 2992 [datetimesent] => 2016-09-22t10:55:12z [datetimecreated] => 2016-09-22t10:55:13z [hasattachments] => [isassociated] => [from] => stdclass object ( [mailbox] => stdclass object ( [name] => basudev kumar sadhu (assistant manager, technology) [mailboxtype] => oneoff ) ) [isread] => ) ) [indexedpagingoffset] => 1 [includeslastiteminrange] => 1 [totalitemsinview] => 1 ) ) ) )
now want parse value output. want capture subject , name output.
below original code used read mail.
<?php require_once ('../mail3/php-ews-master/exchangewebservices.php'); require_once ('../mail3/php-ews-master/ews_exception.php'); require_once ('../mail3/php-ews-master/ewstype.php'); require_once ('../mail3/php-ews-master/ntlmsoapclient.php'); function __autoload($class_name) { // start base path , determine location class name, $base_path = '../mail3/php-ews-master'; $include_file = $base_path . '/' . str_replace('_', '/', $class_name) . '.php'; return (file_exists($include_file) ? require_once $include_file : false); } //$message_id = ''; // id of email message $ews = new exchangewebservices("webmail.bkash.com", "cr.tool", "bangladesh!@34",exchangewebservices::version_2010); $request = new ewstype_finditemtype(); $itemproperties = new ewstype_itemresponseshapetype(); $itemproperties->baseshape = ewstype_defaultshapenamestype::default_properties; $itemproperties->bodytype = ewstype_bodytyperesponsetype::text; $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->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'){ $count = $result->responsemessages->finditemresponsemessage->rootfolder->totalitemsinview; if($count > 0) { echo $count . " email(s)"; print_r($result); } else { echo 'no email(s)'; } } ?>
i suggest using version of library garethp/php-ews
, comes many examples
, including how get list of mail items.
working on that, code like
<?php require_once "vendor/autoload.php"; use garethp\ews\api\type; use garethp\ews\mailapi; $api = mailapi::withusernameandpassword('server', 'username', 'password'); $mail = $api->getmailitems(); foreach ($mail $mailitem) { $mailitem = $api->getitem($mail->getitemid()); $subject = $mailitem->getsubject(); $body = (string) $mailitem->getbody(); }
Comments
Post a Comment