PHP不支持日历消息


Not supported calendar message with PHP

首先,我想说我是一个计算机初学者。

我正在尝试编写一些代码,自动发送包含ics格式的新事件的邮件。我在网上找到了一些代码样本来开始。

我的代码

$desc= 'Rendez-vous dans le cadre de la résolution du ticket'.$ticket_id;
$headers = 'Content-Type:text/calendar; Content-Disposition: inline; charset=utf-8;'r'n';
$headers .= "Content-Type: text/plain;charset='"utf-8'""; #EDIT: TYPO
$message = "BEGIN:VCALENDAR
                            VERSION:2.0
                            PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
                            METHOD:REQUEST
                            BEGIN:VEVENT
                            UID:" . md5(uniqid(mt_rand(), true)) . "example.com
                            DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
                            DTSTART:".$startdate."T".$startTime."00Z
                            DTEND:".$enddate."T".$endTime."00Z
                            TRANSP:OPAQUE
                            SEQUENCE:0
                            SUMMARY:".$subject."
                            ORGANIZER;CN=".$organizer.":mailto:".$organizer_email."
                            LOCATION:".$location.', '.$site."
                            DESCRIPTION:".$desc."
                            PRIORITY:5
                            X-MICROSOFT-CDO-IMPORTANCE:1
                            CLASS:PUBLIC
                            ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:".$participant_email_1."                     
                            END:VEVENT
                            END:VCALENDAR";
$headers .= $message;
mail($participant_email_1, $subject, $message, $headers);   

每个变量都经过验证并且工作正常。正如我在一些讨论中看到的,组织者邮件与邮件的发送者邮件是相同的。

但是当我收到邮件时,outlook说它"不支持日历消息。ics"。下面是message.ics的内容:

BEGIN:VCALENDAR
                            VERSION:2.0
                            PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
                            METHOD:REQUEST
                            BEGIN:VEVENT
                            UID:91090dc834f3536fc3f37af82c1abe3aexample.com
                            DTSTAMP:20160920T142802Z
                             DTSTART:20160923T100000Z
                            DTEND:20160923T12000Z
                            TRANSP:OPAQUE
                            SEQUENCE:0
                            SUMMARY:test
                            ORGANIZER;CN=Marguerite Duras:mailto:example.example@example.example.com
                            LOCATION:Bordeaux, test
                            DESCRIPTION:Rendez-vous dans le cadre de la résolution du ticket17
                            PRIORITY:5
                            X-MICROSOFT-CDO-IMPORTANCE:1
                            CLASS:PUBLIC
                            ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:example.example@example.example.com                      
                            END:VEVENT
                            END:VCALENDAR

我更改了邮件地址,因为这是我的专业地址…有人知道这里出了什么问题吗?对不起,我的英语很接近,我是法国人,在外语方面很糟糕…

非常感谢您的帮助!

每个iCalendar行不能以空格开头。删除每行开头的所有空白,如下所示:

$message = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
METHOD:REQUEST
...
END:VCALENDAR";