Add events to outlook calendar with php script

不羁岁月 提交于 2019-12-03 14:54:10

How your server application should be able to access a client application? You may send an email to your client with a calendar entry. Maybe this is slightly more comfortable for your user.

<?php
/**
 * @category   iCalendar
 * @description Basic code for sending an event invitation.
 * @version    1.0
*/

//Create ICAL Content (Google rfc 2445 for details and examples of usage) 
//reference : http://www.mavetju.org/programming/outlook-ics.php

$message="BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20110718T121000Z
DTEND:20110718T131000Z
DTSTAMP:20110525T075116Z
ORGANIZER;CN=From Name:mailto:from email id
UID:12345678
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Sample:mailto:sample@test.com
DESCRIPTION:This is a test of iCalendar event invitation.
LOCATION: Kochi
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Test iCalendar
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR";

/*Setting the header part, this is important */
$headers = "From: From Name <From Mail>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/calendar; method=REQUEST;\n";
$headers .= '        charset="UTF-8"';
$headers .= "\n";
$headers .= "Content-Transfer-Encoding: 7bit";

/*mail content , attaching the ics detail in the mail as content*/
$subject = "Meeting Subject";
$subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8');

/*mail send*/
if(mail("To email", $subject, $message, $headers)) {

    echo "sent";
}else {
    echo "error";
}

?>

If you've not implemented it yet, CalDAV (http://caldav.calconnect.org/) provides calendaring extensions to WebDAV, if you need to add this functionality to your site. DAViCAL (http://www.davical.org/) appears to offer a solution to your problem but I've not used it so YMMV on it.

I played around with this and Outlook will automatically add it to the calendar if you send it as an email and the from address is the same email address as the account setup in Outlook. As soon as Outlook downloads the message it automatically adds it to the calendar.

I did this with PHP, basically creating an ical event inline on a separate php file that doesn't require any extra libraries for those of you still out there wanting to do it. Outlook/iCal event with PHP

Basically did it like this

echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "PRODID:-//YourSite//NONSGML YourSite//EN\n";
echo "METHOD:PUBLISH\n"; // required by Outlook
echo "BEGIN:VEVENT\n";
echo "UID:".date('Ymd').'T'.date('His')."-".rand()."-yoursite.com\n"; // required by Outlook
echo "DTSTAMP:".date('Ymd').'T'.date('His')."\n"; // required by Outlook
echo "DTSTART:$year"."$month"."$day"."T"."$time\n"; //20120824T093200 (Datetime format required) 
echo "SUMMARY:$summary\n";
echo "DESCRIPTION: this is just a test\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";

You can't.

PHP is a scripting language to create (primarily) web pages, and runs on web servers. It can't modify users' computers.

By the way, I don't think you can - in any way - insert an event into a user's calendar without some kind of user interaction. Beside technical reasons, it's a security issue, you can't go around messing with other peoples' PCs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!