使用php脚本将事件添加到Outlook日历

时间:2011-05-13 09:40:39

标签: php events outlook icalendar

我想从php代码向outlook日历添加事件。由于outlook可以接受扩展名为“.ics”的文件,因此我尝试使用此示例代码生成一个ics文件:

<?php
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=calendar.ics");
echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "PRODID:www.testMeiCalendar.net\n";
echo "METHOD:REQUEST\n"; // requied by Outlook
echo "BEGIN:VEVENT\n";
echo "DTSTART:20101231T230000\n";
echo "DTEND:20110101T010000\n";
echo "SUMMARY:New Years Eve Reminder\n";
echo "LOCATION:Downtown\n";
echo "DESCRIPTION:Let's get together for New Years Eve\n";
echo "UID:ABCD1234\n";
echo "SEQUENCE:0\n";
echo "DTSTAMP:20101125T112600\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";
?>

所以现在当我在Firefox中运行此代码时,我得到一个弹出窗口,要求使用Microsoft Outlook打开生成的ics文件,然后打开它并将其保存到Outlook,最后在Outlook中添加了一个事件。

但是有没有办法让这个过程自动化?我的意思是,我可以直接从php脚本将事件存储在Outlook日历中,而无需生成ics文件并保存吗?

6 个答案:

答案 0 :(得分:5)

<?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";
}

?>

答案 1 :(得分:4)

如果您还没有实现它,CalDAV(http://caldav.calconnect.org/)会提供WebDAV的日历扩展,如果您需要将此功能添加到您的网站。 DAViCAL(http://www.davical.org/)似乎为您的问题提供了解决方案,但我没有使用它,所以YMMV就可以了。

答案 2 :(得分:3)

您的服务器应用程序应该如何访问客户端应用程序?您可以通过日历条目向您的客户发送电子邮件。也许这对您的用户来说稍微舒服一点。

答案 3 :(得分:3)

我玩这个,如果你把它作为电子邮件发送,Outlook会自动将它添加到日历中,并且来自地址的电子邮件地址与Outlook中的帐户设置相同。一旦Outlook下载邮件,它就会自动将其添加到日历中。

答案 4 :(得分:2)

我用PHP做了这个,基本上是在一个单独的php文件上内联创建一个ical事件,不需要任何额外的库,那些你还想要那些人。 Outlook/iCal event with PHP

基本上是这样的

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";

答案 5 :(得分:-3)

你不能。

PHP是一种脚本语言,用于创建(主要)网页,并在Web服务器上运行。它无法修改用户的计算机。

顺便说一下,我认为你不能以任何方式在没有某种用户交互的情况下将事件插入用户的日历中。除了技术原因,这是一个安全问题,你不能四处乱搞其他人的电脑。

相关问题