PHP send multiple event requests in one email to O

2019-08-06 19:10发布

问题:

I have tried below code & was able to send multiple events in one embedded ics to google calendar. But if I open the same mail in MS Outlook 2010 only the first date is displayed in the outlook calendar.

Below is my code.

<?php 
$ical4 = 'BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20150310T183001Z
DTEND:20150310T182959Z
DTSTAMP:20150310T183000Z
UID:2015-03-10_leave_24@gmail.com
ORGANIZER:MAILTO:organizer@gmail.com
ATTENDEE:MAILTO:testuser1@gmail.com
DESCRIPTION:Test E1 Desc
STATUS:CONFIRMED
SEQUENCE:0
SUMMARY:Test E1
TRANSP:OPAQUE
END:VEVENT
BEGIN:VEVENT
DTSTART:20150311T183001Z
DTEND:20150311T182959Z
DTSTAMP:20150310T183000Z
UID:2015-03-11_leave_25@gmail.com
ORGANIZER:MAILTO:organizer@gmail.com
ATTENDEE:MAILTO:testuser1@gmail.com
DESCRIPTION:Test E2 Desc
STATUS:CONFIRMED
SEQUENCE:0
SUMMARY:Test E2
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR';


$from_name = "My Name";
    $from_address = "myname@mydomain.com";
    $subject = "Test Events_1";

//Create Mime Boundry
    $mime_boundary = "----Meeting Booking----".md5(time());

    //Create Email Headers
    $headers = "From: ".$from_name." <".$from_address.">\n";
    $headers .= "Reply-To: ".$from_name." <".$from_address.">\n";

    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
    $headers .= "Content-class: urn:content-classes:calendarmessage\n";

    //Create Email Body (HTML)
    $message = "";
    $message .= "--$mime_boundary\n";
    $message .= "Content-Type: text/html; charset=UTF-8\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";

    $message .= "<html>\n";
    $message .= "<body>\n";
    $message .= '<p>Dear user,</p>';
    $message .= '<p>Here is my HTML Email / Used for Meeting Description</p>';    
    $message .= "</body>\n";
    $message .= "</html>\n";
    $message .= "--$mime_boundary\n";

$message .= 'Content-Type: text/calendar; name="meeting.ics";method=REQUEST; charset=utf-8\n';
$message .= 'Content-Disposition: inline;\n';
    $message .= "Content-Transfer-Encoding: 2048bit\n\n";
    $message .= $ical4; 

    //SEND MAIL
    $mail_sent = @mail( $email, $subject, $message, $headers );

    if($mail_sent)     {
        return true;
    } else {
        return false;
    }   

Note that if I copy the ical content to a .ics file & import to MS Outlook 2010, it gets updated successfully with two events. But, I need to update the outlook calendar automatically by sending a mail using php.

Is there any way how we can send multiple events in one email to MS Outlook 2010 so that it will be automatically added to Outlook calendar?

回答1:

Basically, this doesn't work. iMip messages tend to only have 1 event.

However, one way to work around it, is to turn this into a recurring event with two instances.

To do that, you'll need to make sure that UID is identical for both messages, and one of the messages has a RECURRENCE-ID. The initial (master event) will need to have either RDATE or RRULE to make the event recurring, and the second event will act as an overridden instance.

I don't know how well RDATE works on every client, and I don't know if Outlook 2010 supports it. I do know RRULE is widely supported though.