<p>I'm writing a CMS application in PHP and one of the requirements is that it must be able to interface with the customer's Exchange server.  I've written up this functionality a few times before and have always used <a href="http://en.wikipedia.org/wiki/WebDAV" rel="noreferrer">WebDAV</a> to do it, but now I'm leaning away from that.</p>
<p>I will be running the site on IIS OR Apache (no preference) on Windows server 2008.  A few things I would need to do include adding contacts to a given user's address book, sending emails as a given user and running reports on contacts for a user.</p>
<p>All of this is pretty easy to do with WebDAV, but if there is a better way that doesn't require any functionality that is likely to be deprecated any time soon.</p>
<p>Any ideas?</p>
<h3>Update:</h3>
<p>Justin, I love the idea of using com objects, I just worry about maintaining a 3rd product to make everything work...</p>
<p>John, I can write a web service in C# to interface with for these functions and access it with my PHP app, but it's also a little bit out of the way.</p>
<p>So far, I'm not 100% convinced that either of these is better than WebDAV...</p>
<p>Can anyone show me where I'm being silly?</p>

[{'answer_id': 611, 'author': 'Justin Walgran', 'author_id': 173, 'author_profile': 'https://Stackoverflow.com/users/173', 'pm_score': 3, 'selected': False, 'text': '<p>I\'m not a PHP dev but Google says that PHP 5+ can instantiate COM components. If you can install Outlook on a box you could write a PHP web service around the COM component to handle the requests you need. </p>\n\n<pre><code>$outlook = COM("Outlook.Application")\n</code></pre>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/aa193231.aspx" rel="noreferrer">Outlook API referance</a></p>\n'}, {'answer_id': 633, 'author': 'John', 'author_id': 33, 'author_profile': 'https://Stackoverflow.com/users/33', 'pm_score': 6, 'selected': True, 'text': '<p><strong>Update as of 2020:</strong><br />\nOver a decade since this question and things have moved on. Microsft now has a <a href="https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/office-365-rest-apis-for-mail-calendars-and-contacts" rel="nofollow noreferrer">Rest API</a> that will allow you to easily access this data.</p>\n<hr />\n<p><strong>Original Answer</strong></p>\n<p>I have not used PHP to do this but have experience in using C# to achieve the same thing.</p>\n<p>The Outlook API is a way of automating Outlook rather than connecting to Exchange directly. I have previously taken this approach in a C# application and it does work although can be buggy.</p>\n<p>If you wish to connect directly to the Exchange server you will need to research extended MAPI.</p>\n<p>In the past I used this wrapper <a href="http://www.codeproject.com/KB/IP/CMapiEx.aspx" rel="nofollow noreferrer">MAPIEx: Extended MAPI Wrapper</a>.</p>\n<p>It is a C# project but I believe you can use some .NET code on a PHP5 Windows server. Alternatively it has a C++ core DLL that you may be a able to use. I have found it to be very good and there are some good example applications.</p>\n<hr />\n<p>Sorry for the delay no current way to keep track of posts yet.</p>\n<p>I do agree adding more layer on to your application and relying on 3rd party code can be scary (and rightfully so.)</p>\n<p>Today I read another <a href="https://stackoverflow.com/questions/4508/mapi-and-managed-code-experiences">interesting post</a> tagged up as MAPI that is on a different subject. The key thing here though is that it has linked to <a href="http://blogs.msdn.com/mstehle/archive/2007/10/03/fyi-why-are-mapi-and-cdo-1-21-not-supported-in-managed-net-code.aspx" rel="nofollow noreferrer">this important MS article</a>. I have been unaware of the issues until now on using managed code to interface to MAPI although the C++ code in the component should be unaffected by this error as it is unmanaged.</p>\n<p>This blog entry also suggests other ways to connect to MAPI/Exchange server. In this case due to these new facts <a href="http://us3.php.net/imap" rel="nofollow noreferrer">http://us3.php.net/imap</a> may be the answer as suggested by the other user.</p>\n'}, {'answer_id': 1415, 'author': 'Tim Boland', 'author_id': 70, 'author_profile': 'https://Stackoverflow.com/users/70', 'pm_score': 3, 'selected': False, 'text': '<p>I would look into IMAP</p>\n\n<p><a href="http://us3.php.net/imap" rel="nofollow noreferrer">IMAP, POP3 and NNTP</a></p>\n'}, {'answer_id': 1826, 'author': 'Mike Powell', 'author_id': 205, 'author_profile': 'https://Stackoverflow.com/users/205', 'pm_score': 4, 'selected': False, 'text': '<p>Is your customer using Exchange 2007?  If so, I\'d have a look at <a href="http://msdn.microsoft.com/en-us/library/bb204119(EXCHG.80).aspx" rel="noreferrer">Exchange Web Services</a>.  If not, as hairy as it can be, I think WebDAV is your best bet.  </p>\n\n<p>Personally I don\'t like using the Outlook.Application COM object route, as its security prompts ("An application is attempting to access your contacts.  Allow this?", etc.) can cause problems on a server.  I also think it would be difficult to accomplish your impersonation-like tasks using Outlook, such as sending mail as a given user.</p>\n'}, {'answer_id': 38389, 'author': 'Duncan Smart', 'author_id': 1278, 'author_profile': 'https://Stackoverflow.com/users/1278', 'pm_score': 3, 'selected': False, 'text': '<p>I can\'t recommend Dmitry Streblechenko\'s <a href="http://www.dimastr.com/redemption/rdo_introduction.htm" rel="nofollow noreferrer">Redemption Data Objects</a> library highly enough. It\'s a COM component that provides a sane API to Extended MAPI and is a joy to use. The Exchange API goalposts move from one release to the next: “Use the M: drive! No, use WebDAV! No, use ExOLEDB!… No, use Web Services!” with the only constant being good old MAPI.</p>\n'}, {'answer_id': 5884422, 'author': 'Riley Dutton', 'author_id': 148616, 'author_profile': 'https://Stackoverflow.com/users/148616', 'pm_score': 4, 'selected': False, 'text': '<p>I have released an open-source MIT licensed library that allows you to do some basic operations in PHP using Exchange Web Services.</p>\n\n<p><a href="https://github.com/Heartspring/Exchange-Web-Services-for-PHP" rel="noreferrer">Exchange Web Services for PHP</a></p>\n\n<p>I have only tested it on Linux but I don\'t see any reason why it wouldn\'t work on a Windows installation of PHP as well.</p>\n'}, {'answer_id': 10522246, 'author': 'Scott Szretter', 'author_id': 158438, 'author_profile': 'https://Stackoverflow.com/users/158438', 'pm_score': 3, 'selected': False, 'text': '<p>This <a href="http://developer.zarafa.com/php-ext/" rel="nofollow">Zarafa PHP MAPI</a> extension looks like it could work.</p>\n'}, {'answer_id': 14647212, 'author': 'Valentin Despa', 'author_id': 766177, 'author_profile': 'https://Stackoverflow.com/users/766177', 'pm_score': 3, 'selected': False, 'text': '<p>I would recommend using <strong>"<a href="https://github.com/jamesiarmes/php-ews" rel="noreferrer">PHP Exchange Web Services</a>"</strong> or short <strong>php-ews.</strong></p>\n\n<p>Fair amount of documentation under the <a href="https://github.com/jamesiarmes/php-ews/wiki" rel="noreferrer">wiki</a>, helped me a lot.</p>\n'}, {'answer_id': 52725548, 'author': 'Justin Levene', 'author_id': 1938802, 'author_profile': 'https://Stackoverflow.com/users/1938802', 'pm_score': 3, 'selected': False, 'text': '<p><a href="https://github.com/Garethp/php-ews" rel="noreferrer">https://github.com/Garethp/php-ews</a></p>\n\n<p>It was last updated 3 months ago so it is maintained</p>\n'}]
['https://Stackoverflow.com/questions/588', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/172/']