Best way to access Exchange using PHP?
Asked Answered
H

9

58

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 WebDAV to do it, but now I'm leaning away from that.

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.

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.

Any ideas?

Update:

Justin, I love the idea of using com objects, I just worry about maintaining a 3rd product to make everything work...

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.

So far, I'm not 100% convinced that either of these is better than WebDAV...

Can anyone show me where I'm being silly?

Hoplite answered 3/8, 2008 at 0:3 Comment(2)
I vote for WebDAV. If it can do what you need, stay with it. It's a simple, well-defined interface. COM and consorts are the most flexible but sparsely documented, and often unstable.Hornmad
Can you point to an example of connecting to exchange server with WEBDAV in php? I would like to add a calendar event to exchange server.Breechblock
B
24

Update as of 2020:
Over a decade since this question and things have moved on. Microsft now has a Rest API that will allow you to easily access this data.


Original Answer

I have not used PHP to do this but have experience in using C# to achieve the same thing.

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.

If you wish to connect directly to the Exchange server you will need to research extended MAPI.

In the past I used this wrapper MAPIEx: Extended MAPI Wrapper.

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.


Sorry for the delay no current way to keep track of posts yet.

I do agree adding more layer on to your application and relying on 3rd party code can be scary (and rightfully so.)

Today I read another interesting post tagged up as MAPI that is on a different subject. The key thing here though is that it has linked to this important MS article. 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.

This blog entry also suggests other ways to connect to MAPI/Exchange server. In this case due to these new facts https://www.php.net/imap may be the answer as suggested by the other user.

Burgener answered 3/8, 2008 at 7:50 Comment(0)
D
14

Is your customer using Exchange 2007? If so, I'd have a look at Exchange Web Services. If not, as hairy as it can be, I think WebDAV is your best bet.

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.

Dwell answered 5/8, 2008 at 2:35 Comment(0)
H
12

I have released an open-source MIT licensed library that allows you to do some basic operations in PHP using Exchange Web Services.

Exchange Web Services for PHP

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.

Honest answered 4/5, 2011 at 13:47 Comment(4)
Hi, can you elaborate on how can i create a calendar event on exchange server from my php script?Breechblock
There's a function called "create_event". It should be pretty self-explanatory. github.com/rileydutton/Exchange-Web-Services-for-PHP/blob/…Honest
Thanks, so i need to host the exchange server and integrate it with my php website? And also integrate outlook and exchange server manually? Do you have an idea about php-exchange server integration?Breechblock
At this time (2018 june) this is the most relevant answer.Phenol
L
10

I can't recommend Dmitry Streblechenko's Redemption Data Objects 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.

Liebknecht answered 1/9, 2008 at 20:33 Comment(0)
T
7

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.

$outlook = COM("Outlook.Application")

Outlook API referance

Tarnation answered 3/8, 2008 at 3:7 Comment(1)
This solution is no longer relevant as it is no longer active nor maintainted by Microsoft.Phenol
E
7

I would recommend using "PHP Exchange Web Services" or short php-ews.

Fair amount of documentation under the wiki, helped me a lot.

Eyewitness answered 1/2, 2013 at 13:20 Comment(0)
T
6

This Zarafa PHP MAPI extension looks like it could work.

Tacye answered 9/5, 2012 at 18:47 Comment(1)
This answer is not relevant anymore as it no longer exists.Phenol
P
5

I would look into IMAP

IMAP, POP3 and NNTP

Paresh answered 4/8, 2008 at 17:0 Comment(0)
S
5

https://github.com/Garethp/php-ews

It was last updated 3 months ago so it is maintained

Supernal answered 9/10, 2018 at 16:31 Comment(1)
After spending several days trying different options (including jamesiarmes/php-ews) to connect to our corporate Exchange server 2010 and actually send an email, I tested this library github.com/Garethp/php-ews and it worked out-of-the-box! Thanks to Garethp Parker (the developer) and to Justin Levene for the link!Shay

© 2022 - 2024 — McMap. All rights reserved.