= = = Original message = = =

> Good morning,
> 
> Is it possible to reach the data of the outlook calendar (on a server
> exchange) with php?
> 
> Thank you for advance

I've never tried using PHP to connect to an Exchange server directly, but I've 
done some stuff with using PHP to connect via COM to Outlook itself (and let 
Outlook do all the hard work of getting data from Exchange).

Here's some sample code to read calendar entries.  Remember, you have to have 
Outlook currently running on the PC that PHP is running on.

Good luck!

-TG

<?php
$comobjOutlook = new COM("outlook.application") or die("Unable to instantiate 
outlook"); $comobjOutlook -> Activate;

# This is your mailbox name just like it appears in your Folders view.  It 
might be 'Inbox' or something else.
$targetmailboxname = "Personal Folders";

# This is the folder you're looking for.  In this case, I'm looking for 
calendar items, but you can look for
# any folder.  You need to add another loop to look for subfolders.  Although 
there's probably a better
# way, that's how I did it when I needed to get to Personal 
Folders/Inbox/Subfoldername
$targetfoldername = "Calendar";

$objNamespace = $comobjOutlook->GetNameSpace("MAPI");
$objFolders = $objNamespace->Folders();
$mailboxcount = $objFolders -> Count();

$foundmailbox = FALSE;
for ($i=1; $i<=$mailboxcount; $i++) {
  $folderitem = $objFolders ->Item($i);
  if ($folderitem -> Name == $targetmailboxname) {
    $objMailbox = $folderitem;
    $foundmailbox = TRUE;
  }
}

$foundcal = FALSE;
if ($foundmailbox) {
  $objFolders = $objMailbox->Folders();
  $foldercount = $objFolders -> Count();

  for ($i=1; $i<=$foldercount; $i++) {
    $folderitem = $objFolders -> Item($i);
    if ($folderitem -> Name == $targetfoldername) {
      $objCalendar = $folderitem;
      $foundcal = TRUE;
    }
  }

  if ($foundcal) {
    $objItems = $objCalendar->Items();
    $itemcount = $objItems->Count();

    for ($i=1; $i<=$itemcount; $i++) {
      $apptitem = $objItems -> Item($i);
      $apptstart = $apptitem -> Start();
      $apptend = $apptitem -> End();
      $apptallday = $apptitem -> AllDayEvent();
      $apptrecur = $apptitem -> IsRecurring();
      $apptsubject = $apptitem -> Subject();
      $apptlocation = $apptitem -> Location();

      $secondsadj = $apptstart - 14400;
      $startadj = date("m/d/Y H:i:s", mktime(0,0,$secondsadj,1,1,1970));

      $secondsadj = $apptend - 14400;
      $endadj = date("m/d/Y H:i:s", mktime(0,0,$secondsadj,1,1,1970));

      if($apptallday) { $allday = "All Day"; } else { $allday = ""; }
      if($apptrecur) { $recurring = "Recurring"; } else { $recurring = ""; }

      echo "$apptsubject @ $apptlocation\r\nFrom: $startadj To: $endadj\r\n";
      if ($allday <> "" OR $recurring <> "") echo "$allday $recurring\r\n";
      echo "\r\n\r\n";
    }

  } else {
    die ("Did not find calendar folder");
  }

} else {
  die("Did not find target mailbox: $targetmailboxname");
}
?>



___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to