•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 363,786 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,534 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Does your organization use Microsoft Exchange?
Do you have a need to incorporate your Exchange data with your PHP web applications?
You can use the WebDAV methods to query your Microsoft Exchange Server using the PHP scripting language. Once you wrap your brain around these techniques, the sky is the limit for developing custom Outlook-integrated web applications.
The code below only shows one example of how you can use WebDAV with Exchange. It shows how to iterate over all the subfolders in a user's inbox and display them.
The code below makes use of 2 of my most popular PHP classes:
Do you have a need to incorporate your Exchange data with your PHP web applications?
You can use the WebDAV methods to query your Microsoft Exchange Server using the PHP scripting language. Once you wrap your brain around these techniques, the sky is the limit for developing custom Outlook-integrated web applications.
The code below only shows one example of how you can use WebDAV with Exchange. It shows how to iterate over all the subfolders in a user's inbox and display them.
The code below makes use of 2 of my most popular PHP classes:
- class_http
- class_xml
<?php // Modify the paths to these class files as needed. require_once("class_http.php"); require_once("class_xml.php"); // Change these values for your Exchange Server. $exchange_server = "http://NameOfYourExchangeServer"; $exchange_username = "YourExchangeUsername"; $exchange_password = "YourExchangePassword"; // We use Troy's http class object to send the XML-formatted WebDAV request // to the Exchange Server and to receive the response from the Exchange Server. // The response is also XML-formatted. $h = new http(); $h->headers["Content-Type"] = 'text/xml; charset="UTF-8"'; // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_webdav_depth_header.asp $h->headers["Depth"] = "0"; $h->headers["Translate"] = "f"; // The trickiest part is forming your WebDAV query. This example shows how to // find all the folders in the inbox for a user named 'twolf'. $h->xmlrequest = '<?xml version="1.0"?>'; $h->xmlrequest .= <<<END <a:searchrequest xmlns:a="DAV:" xmlns:s="http://schemas.microsoft.com/exchange/security/"> <a:sql> SELECT "DAV:displayname" FROM SCOPE('hierarchical traversal of "$exchange_server/Exchange/twolf/inbox"') </a:sql> </a:searchrequest> END; // IMPORTANT -- the END line above must be completely left aligned -- no white space at all. // The 'fetch' method does the work of sending and receiving the request. // NOTICE the last parameter passed--'SEARCH' in this example. That is the // HTTP verb that you must correctly set according to the type of WebDAV request // you are making. The examples on this page use either 'PROPFIND' or 'SEARCH'. if (!$h->fetch($exchange_server."/Exchange/twolf/inbox", 0, null, $exchange_username, $exchange_password, "SEARCH")) { echo "<h2>There is a problem with the http request!</h2>"; echo $h->log; exit(); } // Note: The following lines can be uncommented to aid in debugging. #echo "<pre>".$h->log."</pre><hr />\n"; #echo "<pre>".$h->header."</pre><hr />\n"; #echo "<pre>".$h->body."</pre><hr />\n"; #exit(); // Or, these next lines will display the result as an XML doc in the browser. #header('Content-type: text/xml'); #echo $h->body; #exit(); // The assumption now is that we've got an XML result back from the Exchange // Server, so let's parse the XML into an object we can more easily access. // For this task, we'll use Troy's xml class object. $x = new xml(); if (!$x->fetch($h->body)) { echo "<h2>There was a problem parsing your XML!</h2>"; echo "<pre>".$h->log."</pre><hr />\n"; echo "<pre>".$h->header."</pre><hr />\n"; echo "<pre>".$h->body."</pre><hr />\n"; echo "<pre>".$x->log."</pre><hr />\n"; exit(); } // You should now have an object that is an array of objects and arrays that // makes it easy to access the parts you need. These next lines can be // uncommented to make a raw display of the data object. #echo "<pre>\n"; #print_r($x->data); #echo "</pre>\n"; #exit(); // And finally, an example of iterating the inbox folder names and url's to // display in the browser. I also show you 2 methods to link to the folders. // One uses the href provided in the response which opens the folder using OWA. // The other is an Outlook style link to open the folder in the Outlook desktop // client. echo '<table border="1">'; foreach($x->data->A_MULTISTATUS[0]->A_RESPONSE as $idx=>$item) { echo '<tr>' .'<td>'.$item->A_PROPSTAT[0]->A_PROP[0]->A_DISPLAYNAME[0]->_text.'</td>' .'<td><a href="'.$item->A_HREF[0]->_text.'">Click to open via OWA</a></td>' .'<td><a href="Outlook:Inbox/'.$item->A_PROPSTAT[0]->A_PROP[0]->A_DISPLAYNAME[0]->_text.'">Click to open via Outlook</a></td>' ."</tr>\n"; } echo "<table>\n"; ?>
Comments (Newest First)
ahoffman | Newbie Poster | May 1st, 2008
•
•
•
•
I know someone posted the question regarding Forms Based Authentication (FBA) awhile back but it does not look like there was any conclusion. Has anyone been able to develop a version that can be implemented with FBA in place on the Exchange Server? Any assistance would be greatly appreciated.
Thanks,
Aaron
Thanks,
Aaron
sujinss | Newbie Poster | Sep 10th, 2007
•
•
•
•
Hi
to get the subject and content of a mail you can use
SELECT "urn:schemas:httpmail:textdescription" , "urn:schemas:httpmail:subject", "urn:schemas:httpmail:datereceived" FROM "$exchange_server/pillsburylawmail/mailboxnow/Inbox/"
Sujin
to get the subject and content of a mail you can use
SELECT "urn:schemas:httpmail:textdescription" , "urn:schemas:httpmail:subject", "urn:schemas:httpmail:datereceived" FROM "$exchange_server/pillsburylawmail/mailboxnow/Inbox/"
Sujin
vzent | Newbie Poster | May 25th, 2007
•
•
•
•
Hi,
I have downloaded both:
"urn:schemas:httpmail:textdescription" but i just dont know how to create a proper WebDAV query, keep having "400 Bad Request" error.
I tried using the following code to retrieve:
$h->xmlrequest = '<?xml version="1.0"?>';
$h->xmlrequest .= <<<END
<a:searchrequest xmlns:a="DAV:">
<a:sql>
SELECT "urn:schemas:httpmail:subject" FROM "$exchange_server/Exchange/vincent/inbox"
</a:sql>
</a:searchrequest>
END;
I have downloaded both:
- class_http
- class_xml
"urn:schemas:httpmail:textdescription" but i just dont know how to create a proper WebDAV query, keep having "400 Bad Request" error.
I tried using the following code to retrieve:
$h->xmlrequest = '<?xml version="1.0"?>';
$h->xmlrequest .= <<<END
<a:searchrequest xmlns:a="DAV:">
<a:sql>
SELECT "urn:schemas:httpmail:subject" FROM "$exchange_server/Exchange/vincent/inbox"
</a:sql>
</a:searchrequest>
END;
drdal | Newbie Poster | Mar 9th, 2007
•
•
•
•
I have got the example to work... almost that is!
the only error I get now is:
Warning: Invalid argument supplied for foreach() in G:...
any suggestions?
the only error I get now is:
Warning: Invalid argument supplied for foreach() in G:...
any suggestions?
greenie2600 | Newbie Poster | Feb 27th, 2007
•
•
•
•
This looks like it's just what I need for my current project, but I can't get the example to work.
After modifying the connection parameters for my situation, I get the following strange error:
There is a problem with the http request:
New http() object instantiated.
--------------------------------
fetch() called
url: https://exchange.mydomain.net/Exchange/myusername/inbox
getFromUrl() called
Could not open connection. Error 0: The operation completed successfully.
I've twiddled around with this for a while, but I can't get it to work. Anyone have any clues?
After modifying the connection parameters for my situation, I get the following strange error:
There is a problem with the http request:
New http() object instantiated.
--------------------------------
fetch() called
url: https://exchange.mydomain.net/Exchange/myusername/inbox
getFromUrl() called
Could not open connection. Error 0: The operation completed successfully.
I've twiddled around with this for a while, but I can't get it to work. Anyone have any clues?
chakermed | Newbie Poster | Oct 16th, 2006
•
•
•
•
Hi,
I have to extract contacts from an Exchange server over SSL authentification.
---------------------------------------------------------------------------
$exchange_server = "https://mail.justexchange.com/exchange/";
$exchange_username = "demo1@JustExchange.net";
$exchange_password = "Password1!";
---------------------------------------------------------------------------
Using this code I could not connect.
This is the error message I've got:
Warning: fgets() [function.fgets]: SSL: fatal protocol error in C:\wamp\www\asterisk\class_http.php on line 127
Can someone help me PLZ?
I have to extract contacts from an Exchange server over SSL authentification.
---------------------------------------------------------------------------
$exchange_server = "https://mail.justexchange.com/exchange/";
$exchange_username = "demo1@JustExchange.net";
$exchange_password = "Password1!";
---------------------------------------------------------------------------
Using this code I could not connect.
This is the error message I've got:
Warning: fgets() [function.fgets]: SSL: fatal protocol error in C:\wamp\www\asterisk\class_http.php on line 127
Can someone help me PLZ?
smatter.tv | Newbie Poster | Jul 18th, 2006
•
•
•
•
Like HybridDK I am having the same issue. It would be valuable to know how to use this script with FBA compatability.
Thank you to anyone who knows.
- Smatter.tv
Thank you to anyone who knows.
- Smatter.tv
HybridDK | Newbie Poster | Jul 13th, 2006
•
•
•
•
Very interesting script! Just about the only PHP script I've been able to find on this topic.
Im trying to write a script to access the public calendar and publish this to our intranet, but we're using Forms Based Authentication on your exchange server. This means Im not able to use this script because you have to query /exchweb/bin/auth/owaauth.dll with the username and password, save the incoming cookie and further use this to gain access to the goods. Is it possible to make a FBA compatible version of this script?
- HybridDK
Im trying to write a script to access the public calendar and publish this to our intranet, but we're using Forms Based Authentication on your exchange server. This means Im not able to use this script because you have to query /exchweb/bin/auth/owaauth.dll with the username and password, save the incoming cookie and further use this to gain access to the goods. Is it possible to make a FBA compatible version of this script?
- HybridDK
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)