Below is a PHP function that generates vCalendar which can be imported into Outlook.

Notice VTIMEZONE section which specifies timezone. If this section is missing, Outlook will most likely parse the timezone incorrectly.(default to UTC)

 

function generate_vcalendar()
{

$to = ‘anyone@example.com’;
$subject = “Quarterly Meeting”;

$organizer = ‘XXXX’;
$organizer_email = ‘XXX@example.com’;

$participant_name_1 = ‘P1’;
$participant_email_1= ‘P1@example.com’;

$participant_name_2 = ‘P2’;
$participant_email_2= ‘P2@example.com’;

$location = “N/A”;
$date = ‘20150803’;
$startTime = ‘0900’;
$endTime = ‘1000’;
$subject = ‘Quarterly meeting’;
$desc = ‘to send out emails for quarterly meeting’;

$headers = ‘Content-Type:text/calendar; Content-Disposition: inline; charset=utf-8;rn’;
$headers .= “Content-Type: text/plain;charset=”utf-8″rn”;

$message = “BEGIN:VCALENDARrn
VERSION:2.0rn
PRODID:-//somethingUnique//xxx/prod v1.0//ENrn
METHOD:REQUESTrn
BEGIN:VTIMEZONErn
TZID:Australia/Sydneyrn
BEGIN:STANDARDrn
DTSTART:16010101T000000rn
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4rn
TZOFFSETFROM:+1100rn
TZOFFSETTO:+1000rn
TZNAME:Standard Timern
END:STANDARDrn
BEGIN:DAYLIGHTrn
DTSTART:16010101T000000rn
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=10rn
TZOFFSETFROM:+1000rn
TZOFFSETTO:+1100rn
TZNAME:Daylight Saving Timern
END:DAYLIGHTrn
END:VTIMEZONErn
BEGIN:VEVENTrn
UID:” . md5(uniqid(mt_rand(), true)) . “example.comrn
DTSTAMP:” . gmdate(‘Ymd’).’T’. gmdate(‘His’) . “rn
DTSTART;TZID=”. “Australia/Sydney” . “:”.$date.”T”.$startTime.”00rn
DTEND;TZID=” . “Australia/Sydney” . “:”.$date.”T”.$endTime.”00rn
SUMMARY:”.$subject.”rn
ORGANIZER;CN=”.$organizer.”:mailto:”.$organizer_email.”rn
LOCATION:”.$location.”rn
DESCRIPTION:”.$desc.”rn
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN”.$participant_name_1.”;X-NUM-GUESTS=0:MAILTO:”.$participant_email_1.”rn
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN”.$participant_name_2.”;X-NUM-GUESTS=0:MAILTO:”.$participant_email_2.”rn
END:VEVENTrn
END:VCALENDARrn”;

$headers .= $message;
mail($to, $subject, $message, $headers);
}

vCalendar by PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

2 + 7 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.