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

标签 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 文件并保存吗?

最佳答案

<?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/

相关文章:

php - openssl_encrypt 返回 false

php - 从 php 'template' 创建并保存纯 html 文件?

c++ - 有效关联事件

javascript - jQuery 事件在 .load() 之后触发两次

excel - 使用 Excel VBA 在主题和附件中查找包含关键字的 Outlook 电子邮件

php - PDO::prepare 和 PDO::quote 完全安全吗?

php - 这是执行 mysql 查询的正确方法吗

events - Angular2 点击事件未触发

excel - 如何在带有邮件线程的 excel 中使用 vba 回复 Outlook 邮件?

php - 使用 php 读取 .pst 文件的内容