Ical .ics不可由Office 365读取

时间:2015-12-08 16:15:07

标签: outlook google-calendar-api phpmailer icalendar

我试图向Ical和PhpMailer发送会议请求。我通过邮件加入Ical作为StringAttachment。如果我下载附件,我可以用桌面Outlook阅读它,但我尝试用Office 365打开它,我有一个警告说:" .ICS附件无法查看,因为格式是不支持。"。在谷歌日历上我也无法导入它。

$ical = "BEGIN:VCALENDAR\r\n";
$ical .= "VERSION:2.0\r\n";
$ical .= "METHOD:REQUEST\r\n";  
$ical .= "BEGIN:VEVENT\r\n";
$ical .= "BEGIN:VTIMEZONE\r\n";
$ical .= "TZID:Europe/Paris\r\n";
$ical .= "X-LIC-LOCATION:Europe/Paris\r\n";
$ical .= "BEGIN:DAYLIGHT\r\n";
$ical .= "TZOFFSETFROM:+0100\r\n";
$ical .= "TZOFFSETTO:+0200\r\n";
$ical .= "TZNAME:CEST\r\n";
$ical .= "DTSTART:19700329T020000\r\n";
$ical .= "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3\r\n";
$ical .= "END:DAYLIGHT\r\n";
$ical .= "BEGIN:STANDARD\r\n";
$ical .= "TZOFFSETFROM:+0200\r\n";
$ical .= "TZOFFSETTO:+0100\r\n";
$ical .= "TZNAME:CET\r\n";
$ical .= "DTSTART:19701025T030000\r\n";
$ical .= "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10\r\n";
$ical .= "END:STANDARD\r\n";
$ical .= "END:VTIMEZONE\r\n"; 
$ical .= "ORGANIZER:MAILTO:hgdfsghdsfghsd@gmail.com\r\n";
$ical .= "ATTENDEE;PARTSTAT=ACCEPTED:MAILTO:ghhgjkgh@gmail.com\r\n";
$ical .= "UID:".strtoupper(md5($interId))."-*****.fr\r\n";
$ical .= "METHOD:REQUEST\r\n";
$ical .= "SEQUENCE:1";
$ical .= "STATUS:".$status."\r\n";
$ical .= "DTSTART:".$startDate->format('Ymd').'T'.$startDate->format('His')."\r\n";
$ical .= "DTEND:".$endDate->format('Ymd').'T'.$endDate->format('His')."\r\n";
$ical .= "LOCATION:".$shopName."\r\n";
$ical .= "SUMMARY:".$summary."\r\n";
$ical .= "DESCRIPTION:\r\n";
$ical .= "BEGIN:VALARM\r\n";
$ical .= "TRIGGER:-PT15M\r\n";
$ical .= "ACTION:DISPLAY\r\n";
$ical .= "DESCRIPTION:Reminder\r\n";
$ical .= "END:VALARM\r\n";
$ical .= "END:VEVENT\r\n";
$ical .= "END:VCALENDAR\r\n";

$mail->AddStringAttachment($ical, "Invite.ics", "base64", "text/calendar; charset=utf-8; method=REQUEST");

我希望gmail和office 365可以读取邀请,但我不明白我的有什么问题。你有什么想法吗?

由于

2 个答案:

答案 0 :(得分:1)

一些问题:

1)VEVENT组件中的DTSTART和DTEND属性缺少TZID参数。

$ical .= "DTSTART;TZID=Europe/Paris:".$startDate->format('Ymd').'T'.$startDate->format('His')."\r\n";
$ical .= "DTEND;TZID=Europe/Paris:".$endDate->format('Ymd').'T'.$endDate->format('His')."\r\n";

2)VTIMEZONE组件不应位于VEVENT组件内。它应该在VCALENDAR组件下面。

BEGIN:VCALENDAR
VERSION:2.0
METHOD:REQUEST
BEGIN:VTIMEZONE
...
END:VTIMEZONE
BEGIN:VEVENT
...
END:VEVENT
END:VCALENDAR

答案 1 :(得分:-1)

您的第二个错误可能是由VEVENT组件内的METHOD属性引起的。 METHOD应该只在VCALENADAR组件内部发生。