Home > General, Technology > SendItem: Accessing Exchange 2007 with PHP-Soap

SendItem: Accessing Exchange 2007 with PHP-Soap

February 21st, 2009

This is going to be one of those mostly technical posts to help others who are struggling with using PHP-Soap to access Exchange 2007 web services. Apologies to regular readers who are not familiar with PHP and Exchange 2007. If you find this helpful, please leave a comment below.

Start at the Beginning

To get started, you’ll need to read Erik Cederstand’s HOWTO talk SOAP with Exchange and get the fundamental stuff working.  For some common problems, also check out the ongoing thread http://www.howtoforge.com/forums/showthread.php?p=171001 . Additionally, the MSDN reference at http://msdn.microsoft.com/en-us/default.aspx is where you need to educate yourself on Exchange Web Services, XML, and error messages.

Know what XML you are forming

The Microsoft Developer’s Network is the place to start for XML examples. Here’s the XML we’ll form for our CreateItem example:

/*

<?xml version=”1.0″ encoding=”utf-8″ ?> <CreateItem xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” MessageDisposition=”SendAndSaveCopy”>

<SavedItemFolderId xmlns=”http://schemas.microsoft.com/exchange/services/2006/messages”> <DistinguishedFolderId Id=”sentitems” xmlns=”http://schemas.microsoft.com/exchange/services/2006/types” /> </SavedItemFolderId>

<Items xmlns=”http://schemas.microsoft.com/exchange/services/2006/messages”>

<Message xmlns=”http://schemas.microsoft.com/exchange/services/2006/types”> <ItemClass>IPM.Note</ItemClass>

<Subject>YOUR SUBJECT</Subject>

<Body BodyType=”Text”>YOUR BODY TEXT</Body>

<ToRecipients> <Mailbox> <EmailAddress>SOMEONE@e-oasis.com</EmailAddress> </Mailbox>

</ToRecipients> </Message> </Items> </CreateItem>

*/

Use PHP-Soap to form the XML request

Debugging Soap errors can be frustrating, but if you “stare and compare” against your XML you can typically find the problem. Here’s the PHP code to form the XML request. Note how the attribute of BodyType is passed within the Body tag using Body['BodyType'] and the content of the Body tag is passed with Body[_] = “YOUR BODY TEXT”; .

//CreateItem Sends e-mail through Exchange 2007 $CreateItem->MessageDisposition=”SendAndSaveCopy”; $CreateItem->SavedItemFolderId->DistinguishedFolderId->Id = “inbox”; $CreateItem->Items->Message = array();

for($i = 0; $i < 1; $i++) {

$CreateItem->Items->Message[$i]->ItemClass = “IPM.Note”; $CreateItem->Items->Message[$i]->Subject = “YOUR SUBJECT“; $CreateItem->Items->Message[$i]->Body[_] = “YOUR BODY TEXT“; $CreateItem->Items->Message[$i]->Body['BodyType'] = “Text“; $CreateItem->Items->Message[$i]->ToRecipients->Mailbox->EmailAddress = “SOMEONE@e-oasis.com“;

$CreateItem->Items->Message[$i]->IsRead = “false”;

}

$result = $client->CreateItem($CreateItem);

Was this helpful?

If you found this helpful, we’d appreciate a comment or other PHP-Soap examples that can help others.  Until PHP-Soap access to Exchange 2007 becomes more common-place, these examples will be huge time-savers for everyone.

E-Mail blaine@e-oasis.com or twitter @e0asis

Can you find @eoasis on Twitter?
  • Twitter
  • email
  • LinkedIn

General, Technology

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.