使用 php 脚本将事件添加到 Outlook 日历
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5990017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add events to outlook calendar with php script
提问by shasi kanth
I want to add events to my outlook calendar from the php code. As outlook can accept a file of extension ".ics", I have tried this sample code to generate an ics file:
我想通过 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";
?>
So now when I run this code in Firefox, I got a pop-up asking to open the generated ics file using the Microsoft Outlook and I opened it and saved it to outlook and finally an event is added in outlook.
所以现在当我在 Firefox 中运行这段代码时,我收到一个弹出窗口,要求使用 Microsoft Outlook 打开生成的 ics 文件,我打开它并将其保存到 Outlook,最后在 Outlook 中添加了一个事件。
But is there a way I can automate this process? I mean, can I store the event in Outlook calendar directly from a php script, without needing to generate an ics file and saving it?
但是有没有办法让这个过程自动化?我的意思是,我可以直接从 php 脚本将事件存储在 Outlook 日历中,而无需生成 ics 文件并保存它吗?
采纳答案by DanielB
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.
您的服务器应用程序应该如何访问客户端应用程序?您可以向您的客户发送一封带有日历条目的电子邮件。也许这对您的用户来说更舒服一些。
回答by Haneefa
<?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:[email protected]
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";
}
?>
回答by ipe
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.
如果您还没有实现它,CalDAV (http://caldav.calconnect.org/) 为 WebDAV 提供日历扩展,如果您需要将此功能添加到您的站点。DAViCAL (http://www.davical.org/) 似乎为您的问题提供了解决方案,但我没有使用过它,所以 YMMV 就在上面。
回答by Pitchinnate
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.
我对此进行了处理,如果您将其作为电子邮件发送并且发件人地址与 Outlook 中的帐户设置相同,则 Outlook 会自动将其添加到日历中。Outlook 下载邮件后,它会自动将其添加到日历中。
回答by Drazion
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
我用 PHP 做到了这一点,基本上是在一个单独的 php 文件上创建一个内联的 ical 事件,对于那些仍然想要这样做的人来说,它不需要任何额外的库。使用 PHP 的 Outlook/iCal 事件
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";
回答by Albireo
You can't.
你不能。
PHP is a scripting language to create (primarily) web pages, and runs on web servers. It can't modify users' computers.
PHP 是一种用于创建(主要)网页的脚本语言,并在 Web 服务器上运行。它不能修改用户的计算机。
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.
顺便说一句,我不认为您可以 - 以任何方式 - 在没有某种用户交互的情况下将事件插入到用户的日历中。除了技术原因,这是一个安全问题,你不能到处乱搞别人的电脑。