Outlook 2013显示“不支持的日历message.ics”,但Gmail,Outlook 2007很好

时间:2017-02-20 16:28:06

标签: php outlook icalendar

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

以下是生成的ics示例:

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@demoemailaddress.com
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:customer@demoemailaddress.com
SUMMARY:Test website for evet
DESCRIPTION:xyz
LOCATION:tbc
SEQUENCE:0
UID:ICAL_128_NTG47K1VYJ@www.companydomain.com
END:VEVENT
END:VCALENDAR

感谢您的帮助!

3 个答案:

答案 0 :(得分:1)

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

我遇到了一些问题,新的Outlook非常特别关于它是否会接受我的事件而没有奇怪的问题...... 并且其中很多实际上归结为正确的行结尾。我必须确保在VCalendar代码中使用\r\n,但在Unix上的PHP中,我必须确保\n用于实际电子邮件中的新行。以下是我使用最新Outlook的一些代码,它使用字符串数组,以便每个部分的行结尾都是明确且明显的:

  

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

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

    $uid                = "0123456789";
    $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>");

请随时在应用程序/网站上添加对此有用或无效的评论。 THX。

答案 1 :(得分:0)

尝试在Outlook中创建约会,然后使用.ics格式保存。有关更多信息,请参阅How To Save A Selected Appointment As Ics File In Outlook?。然后,您可以打开已保存的文件,并将其内容与以编程方式生成的文件进行比较。

答案 2 :(得分:0)

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