使用 php 脚本将事件添加到 Outlook 日历
我想从 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 中运行此代码时,我收到一个弹出窗口,要求使用以下命令打开生成的 ics 文件:我和 Microsoft Outlook 打开它并将其保存到 Outlook,最后在 Outlook 中添加了一个事件。
但有没有办法让这个过程自动化呢?我的意思是,我可以直接从 php 脚本将事件存储在 Outlook 日历中,而不需要生成 ics 文件并保存吗?
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
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您尚未实现,CalDAV (http://caldav.calconnect.org/) 提供了 WebDAV 的日历扩展(如果您需要将此功能添加到您的站点)。 DAViCAL(http://www.davical.org/)似乎为您的问题提供了解决方案,但我还没有使用过它,所以 YMMV 就可以了。
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.
您的服务器应用程序应该如何访问客户端应用程序?您可以向您的客户发送一封包含日历条目的电子邮件。也许这对您的用户来说稍微更舒服一些。
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.
我对此进行了尝试,如果您将其作为电子邮件发送,并且发件人地址与 Outlook 中的帐户设置相同,则 Outlook 会自动将其添加到日历中。 Outlook 下载邮件后,它会自动将其添加到日历中。
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.
我用 PHP 做到了这一点,基本上是在一个单独的 php 文件上内联创建一个 ical 事件,对于那些仍然想要这样做的人来说,不需要任何额外的库。 Outlook/iCal 事件PHP
基本上就是这样做的
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
你不能。
PHP 是一种用于创建(主要)网页的脚本语言,并在 Web 服务器上运行。它无法修改用户的计算机。
顺便说一句,我认为您无法在没有某种用户交互的情况下以任何方式将事件插入用户的日历中。除了技术原因之外,这是一个安全问题,你不能到处乱搞别人的电脑。
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.