2017-02-20 186 views
0

我的PHP程序生成一个ics文件,它以前适用于大多数电子邮件客户端,但我得到了Outlook 2013的错误,文件名名为“不支持日历message.ics”的ics文件,但双击打开它时会正确显示内容。我搜索互联网,但找不到任何理由。任何人都可以帮助这种情况?Outlook 2013显示“不支持日历message.ics”,但Gmail,Outlook 2007很好

这里是产生集成电路例如:

BEGIN:VCALENDAR 
PRODID:-//MY COMPANY NAME//System iCal Generator//EN 
VERSION:2.0 
METHOD:REQUEST 
BEGIN:VEVENT 
DTSTART:20170314T180000Z 
DTEND:20170314T210000Z 
DTSTAMP:20170217T161443Z 
ORGANIZER;CN=name of event here:mailto:[email protected] 
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:[email protected] 
SUMMARY:Test website for evet 
DESCRIPTION:xyz 
LOCATION:tbc 
SEQUENCE:0 
UID:[email protected] 
END:VEVENT 
END:VCALENDAR 

感谢您的帮助!

+0

在Outlook中出现什么错误? –

回答

0

一个旧的,但我会继续并回答,因为它出现在我的搜索。

我有一些问题与新的Outlook非常关心它是否会接受我的事件没有奇怪的问题... 和它的很多实际上归结为适当的行尾。我必须确保在VCalendar代码中使用,但在Unix上的PHP中,我必须确保\n用于实际电子邮件中的新行。下面是我使用最新的Outlook工作的一些代码,它使用字符串数组,以便每个部分的行结束是明确的和明显的:

请注意,此代码不会阻止标头注入。 请使用负责任:)

<?php 
    date_default_timezone_set('America/New_York'); 
    //CONFIGURE HERE 
    $fromName   = "John Doe"; 
    $fromEmail   = "[email protected]"; 
    $toName    = "Your Name"; 
    $toEmail   = isset($_GET['to']) ? $_GET['to'] : '[email protected]'; 
    $start    = new DateTime('2017-08-15 15:00'); 
    $end    = new DateTime('2017-08-15 16:00'); 
    $summary   = "Hello World Event"; 
    //END CONFIGURATION 

    $uid    = ""; 
    $headers   = array(); 
    $boundary   = "_CAL_" . uniqid("B",true) . "_B_"; 
    $headers[]   = "MIME-Version: 1.0"; 
    $headers[]   = "Content-Type: multipart/alternative; boundary=\"".$boundary."\""; 
    $headers[]   = "To: \"{$toName}\" <{$toEmail}>"; 
    $headers[]   = "From: \"{$fromName}\" <{$fromEmail}>"; 

    $calendarLines  = array(
     "BEGIN:VCALENDAR", 
     "METHOD:REQUEST", 
     "PRODID:-//PHP//MeetingRequest//EN", 
     "VERSION:2.0", 
     "BEGIN:VEVENT", 
     "ORGANIZER;CN={$fromName}:MAILTO:{$fromEmail}", 
     "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN={$toName}:MAILTO:{$toEmail}", 
     "DESCRIPTION:{$summary}", 
     "SUMMARY:{$summary}", 
     "DTSTART:".$start->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z'), 
     "DTEND:".$end->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z'), 
     "UID:{$uid}", 
     "CLASS:PUBLIC", 
     "PRIORITY:5", 
     "DTSTAMP:".gmdate('Ymd\THis\Z'), 
     "TRANSP:OPAQUE", 
     "STATUS:CONFIRMED", 
     "SEQUENCE:0", 
     "LOCATION:123 Any Street", 
     "BEGIN:VALARM", 
     "ACTION:DISPLAY", 
     "DESCRIPTION:REMINDER", 
     "TRIGGER;RELATED=START:-PT15M", 
     "END:VALARM", 
     "END:VEVENT", 
     "END:VCALENDAR" 
    ); 


    $calendarBase64  = base64_encode(implode("\r\n",$calendarLines)); 
    //ensure we don't have lines longer than 70 characters for older computers: 
    $calendarResult  = wordwrap($calendarBase64,68,"\n",true); 

    $emailLines = array(
     "--{$boundary}", 
     "Content-Type: text/html; charset=\"iso - 8859 - 1\"", 
     "Content-Transfer-Encoding: quoted-printable", 
     "", 
     "<html><body>", 
     "<h1>Hello World</h1>", 
     "<p>This is a calendar event test</p>", 
     "</body></html>", 
     "", 
     "--{$boundary}", 
     "Content-Type: text/calendar; charset=\"utf - 8\"; method=REQUEST", 
     "Content-Transfer-Encoding: base64", 
     "", 
     $calendarResult, 
     "", 
     "--{$boundary}--" 
    ); 
    $emailContent = implode("\n",$emailLines); 

    $headersResult  = implode("\n",$headers); 
    mail($toEmail, $summary, $emailContent, $headersResult); 
    echo("<pre>".htmlentities($headersResult)."\n\n".htmlentities($emailContent)."</pre>"); 
    echo("<br /><br />"); 
    echo("<pre>".base64_decode($calendarResult)."</pre>"); 

请随时上的应用程序/网站,这样做或不工作添加注释。谢谢。

0

使用icalendar验证程序在https://icalendar.org/validator.html处测试您的icalendar供稿,它发现ATTENDEE行超过75个字符,这是icalendar文件的最大行大小。也许这就是为什么它不起作用?