sha*_*nth 6 php events icalendar 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";
?>
Run Code Online (Sandbox Code Playgroud)
所以现在当我在Firefox中运行此代码时,我得到一个弹出窗口,要求使用Microsoft Outlook打开生成的ics文件,然后打开它并将其保存到Outlook,最后在Outlook中添加了一个事件.
但有没有办法让这个过程自动化?我的意思是,我可以直接从php脚本将事件存储在Outlook日历中,而无需生成ics文件并保存吗?
小智 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";
}
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33699 次 |
| 最近记录: |