我想通过 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 文件并保存吗?
最佳答案
<?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";
}
?>
关于php - 使用 php 脚本将事件添加到 outlook 日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5990017/