Originally published on: 2/6/2006 6:20:28 AM
Here's another piece in what is shaping up to be a string of tools for managing this kind of thing. This creates an Outlook task for taking daily notes on what happened each day. It will be run each Monday to create a task with a due date of Friday. The subject will contain the dates for the Sun-Sat current week.
It also serves as a fairly simple example of creating tasks in Outlook automatically. The code is commented to explain what's going on. As with the previous solution, I'm using the Windows task scheduler to have this kick off on Monday morning. I'll likely write something up to easily "self-schedule" as well as I am already irritated at having to manually set these up even the once. (I know, low tolerance for irritability).
< ?php
/* Define Outlook number for Task Item */
$olTaskItem = 3;
/* Create an instance of Outlook */
$ol = new COM("Outlook.Application");
/* Create a Task Item */
$task = $ol->CreateItem($olTaskItem);
/*
Set dates for current week.
PHP's strtotime needs the chosen strings to give us the Sun-Sat week.
If you choose to use a Mon-Fri week, the "last" becomes "this" for the beginning.
It's just how PHP and strtotime work.
*/
$begin = date("m/d/y", strtotime("last Sunday"));
$end = date("m/d/y", strtotime("this Saturday"));
$due = date("m/d/y", strtotime("this Friday"));
/* Set some properties of the task */
$task->Subject = "Milestone Notes for $begin to $end";
$task->DueDate = $due;
$task->Body = "Insert the template text for your task";
/* Save the Task */
$task->Save();
print("Done");
?>
If you're curious about modifying the task a little more, you can see the complete list of properties (Subject, Body, DueDate, etc.) and Methods (like Save) in the Outlook documentation for the TaskItem. Most of the examples are in VBScript, but that's generally the case with Office documentation. However, use my sample script as your guide and you can pretty quickly see the syntax conversion you need to do to make their examples work (is there interest in a post showing how to more generally convert VBScript or Javascript into PHP?).
Thanks for your help
The biggest syntax change is that PHP uses $object->property syntax while VBScript uses object.property. Also, whenever you see a constant like
myOlApp.CreateItem(olTaskItem)
the "olTaskItem" is a constant that you'll have to look up. The constant is often just "there" if you're doing it in VBA, but in PHP, you'll need the actual value of "3" instead.
In Outlook, you can defintely assign tasks. Effectively, you can do pretty much anything with COM in Outlook that you can do manually. That's really the power of the automation stuff. In the above code, once you reach the point where you're setting properties:
$task->Subject = "Subject";
The variable $task is what the Outlook object model calls an "Item". It's specifically a TaskItem. If you look in the Outlook documentation at the object "TaskItem", you will see all of the properties and methods you can use on a task.
The Outlook object model is described here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_2003_ta/html/odc_landoffice03_vba.asp
TaskItems are described here:
http://msdn.microsoft.com/library/en-us/vbaol11/html/olobjTaskItem_HV05247372.asp?frame=true
Down at the bottom of that documentation page is a huge list of those properties an methods. "Save()" is one of those that I used in my sample. For your project, you'll want to look at "Assign" to send them out and possibly "Mark Complete" and "Delete" if you want to cancel from the same place you're assigning.
Take a look at the VB examples and compare them with my PHP above and you should see the patterns you'll need to convert all of the example code into PHP.
Oh. You may also need to install a program that I don't have the name/URL of handy that overrides Outlook's tight security to enable your app to really dig into Outlook.
Warning: (null)(): Invoke() failed: Type mismatch. Argument: 2
i have tested this code but i think there is something wrong. i have outlook 2003, win xp, and php 4, is there any issue with outlook 2003 and the foloing code?
sorry about my english (i'm portugese)
thanks ;)
Need to know where I can find list of valid commands, ie, Worksheet->Add(); for excel COM objects.
Can you help?
But getting the error as :
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `Outlook.Application.11': Server execution failed ' in C:\Program Files\Apache Group\Apache2\htdocs\powerplate\test4.php:2 Stack trace: #0 C:\Program Files\Apache Group\Apache2\htdocs\powerplate\test4.php(2): com->com('Outlook.Applica...') #1 {main} thrown in C:\Program Files\Apache Group\Apache2\htdocs\powerplate\test4.php on line 2
I have isntalled Windows XP / MSOutlook 2003 /Apache 2.054 /PHP 5.0.3
Please help
as i want to develop a webbased tool in PHP4, which sends tasks and meetings to my outlook as an email (as if somebody else would send me the task from his outlook), i wonder, how the task can be sent.
i already managed to send me meetings with the vCalendar standard used in Outlook:
BEGIN: VEVENT
...
END: VEVENT
As in Outlook 2003 the VTODO does not exist, I don't know how to continue.
Can anybody help me? Do I need to install someting particular on the webserver that I can make use of the Outlook Object with PHP?
Regards
Pascal
Unable to connect to Outlook: Failed to create COM object `Outlook.Application': Call was rejected by callee.
Would appreciate very much for helping. Thanks
This script seem don't word with outlook 2003 / 2007.
Someone can help me ?
Thanks.