我没有运气使用 php-ews 从 Exchange 2010 服务器获取电子邮件的消息正文。这是我的代码:
$ews = new ExchangeWebServices("hostname", "username","password",ExchangeWebServices::VERSION_2010);
$request = new EWSType_FindItemType();
$itemProperties = new EWSType_ItemResponseShapeType();
$itemProperties->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$itemProperties->BodyType = EWSType_BodyTypeResponseType::BEST;
$request->ItemShape = $itemProperties;
//If I do not include the below three sentences I get a PHP Fatal error saying "Basepoint" not found
$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'){
$message = $result->ResponseMessages->FindItemResponseMessage->Items->Message;
//This if loop is entered but the $message variable contains nothing
print_r($message);exit;
//var_dump($message) displays NULL
}
进入“if”循环,但 $message 变量不包含任何内容。通常它应该是一个对象,我可以从中检索电子邮件的正文。
我究竟做错了什么 ?
我在 if() 语句中尝试了这个,我得到了 $message 对象:
$message = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->Message;
print_r($message);exit;
缺少“RootFolder”属性。但是,生成的 $message 变量不包含任何包含电子邮件正文的“正文”属性。这就是 print_r($message) 的样子:
stdClass Object
( [ItemId] => stdClass Object ( [Id] => AAMkADZjOTZhNjNkLTBmZTAtNDdkZi04NGI5LTdiZWY0ZWYzOGNhMwBGAAAAAABI9LX/rIDdRr5XMdDM8RGZBwAL3uOTQAYYQ4U8CTQP/+wKAAAAWsnbAAAL3uOTQAYYQ4U8CTQP/+wKAAAAWvd0AAA= [ChangeKey] => CQAAABYAAAAL3uOTQAYYQ4U8CTQP/+wKAAAAWyCi )
[ParentFolderId] => stdClass Object
(
[Id] => AQMkADZjOTZhNjNkLTBmZTAtNDdkZi04NGI5LTdiZWY0ZWYzOGNhMwAuAAADSPS1/6yA3Ua+VzHQzPERmQEAC97jk0AGGEOFPAk0D//sCgAAAVrJ2wAAAA==
[ChangeKey] => AQAAAA==
)
[ItemClass] => IPM.Note
[Subject] => Test
[Sensitivity] => Normal
[DateTimeReceived] => 2012-09-05T13:03:08Z
[Size] => 4754
[Importance] => Normal
[IsSubmitted] =>
[IsDraft] =>
[IsFromMe] =>
[IsResend] =>
[IsUnmodified] => 1
[DateTimeSent] => 2012-09-05T13:03:00Z
[DateTimeCreated] => 2012-09-05T13:03:08Z
[DisplayCc] =>
[DisplayTo] => sara cooper
[HasAttachments] =>
[Culture] => en-IN
[EffectiveRights] => stdClass Object
(
[CreateAssociated] =>
[CreateContents] =>
[CreateHierarchy] =>
[Delete] => 1
[Modify] => 1
[Read] => 1
)
[LastModifiedName] => Lin T
[LastModifiedTime] => 2012-09-05T13:03:08Z
[IsAssociated] =>
[WebClientReadFormQueryString] => ?ae=Item&a=Open&t=IPM.Note&id=RgAAAABI9LX%2frIDdRr5XMdDM8RGZBwAL3uOTQAYYQ4U8CTQP%2f%2bwKAAAAWsnbAAAL3uOTQAYYQ4U8CTQP%2f%2bwKAAAAWvd0AAAJ&exvsurl=1
[ConversationId] => stdClass Object
(
[Id] => AAQkADZjOTZhNjNkLTBmZTAtNDdkZi04NGI5LTdiZWY0ZWYzOGNhMwAQAJ56TrE0QUIAk59ALIqWrrY=
)
[Sender] => stdClass Object
(
[Mailbox] => stdClass Object
(
[Name] => Lin T
[MailboxType] => OneOff
)
)
[IsReadReceiptRequested] =>
[ConversationIndex] => Í‹fÃIžzN±4AB“Ÿ@,Š–®¶
[ConversationTopic] => Test
[From] => stdClass Object
(
[Mailbox] => stdClass Object
(
[Name] => Lin T
[MailboxType] => OneOff
)
)
[InternetMessageId] => <027d01cd8b66$c8c967e0$5a5c37a0$@marlabs.com>
[IsRead] =>
[ReceivedBy] => stdClass Object
(
[Mailbox] => stdClass Object
(
[Name] => sara cooper
[MailboxType] => OneOff
)
)
[ReceivedRepresenting] => stdClass Object
(
[Mailbox] => stdClass Object
(
[Name] => sara cooper
[MailboxType] => OneOff
)
)
)
我还需要发件人和收件人的电子邮件地址。这里只显示名字和姓氏。请帮助这变得非常紧迫。