I need to submit an Outlook Calendar event with attached .ics-file from my PHP application. After i searched for several hours i found a very hugh number of ways which are not working at the same time for the iPhone (using .ics), Thunderbird (using Lightning plugin) and for (Exchange-) Outlook. Also this are so few lines of code.

For everybody with the same problem ( and for myself for the next application ), here is the outcoming method (not too well documented but by playing with the parameters you’ll get it very fast):

/**
 * sends an iCal event mail
 * @param Timestamp $tsStart - timestart of the start time
 * @param Timestamp $tsEnd - timestamp of end date
 * @param String $location - location of event
 * @param String $summary - event summary
 * @param String $to - list of email recipients
 * @param String $subject - email subject
 */
private function sendCalEntry( $tsStart, $tsEnd, $location, $summary, $title, $resources, $to, $subject ){
 
	$from = ORGANISATIONREPLYMAIL;
	$dtstart = date('Ymd',$tsStart).'T'.date('His',$tsStart);
	$dtend = date('Ymd',$tsEnd).'T'.date('His',$tsEnd);
	$loc = $location;
 
	$vcal = "BEGIN:VCALENDAR\r\n";
	$vcal .= "VERSION:2.0\r\n";
	$vcal .= "PRODID:-//nonstatics.com//OrgCalendarWebTool//EN\r\n";
	$vcal .= "METHOD:REQUEST\r\n";
	$vcal .= "BEGIN:VEVENT\r\n";
	$vcal .= "ORGANIZER;CN=\"".ORGANISATIONNAME." (".$_SESSION['username'].")"."\":mailto:".ORGANISATIONREPLYMAIL."\r\n";
	$vcal .= "UID:".date('Ymd').'T'.date('His')."-".rand()."-nonstatics.com\r\n";
	$vcal .= "DTSTAMP:".date('Ymd').'T'.date('His')."\r\n";
	$vcal .= "DTSTART:$dtstart\r\n";
	$vcal .= "DTEND:$dtend\r\n"; 
	$vcal .= "LOCATION:$location\r\n";
	$vcal .= "SUMMARY:$summary\r\n";
	$vcal .= "DESCRIPTION:Hinweis/Fahrer:$summary - Folgende Resourcen wurden gebucht: $resources \r\n";
	$vcal .= "BEGIN:VALARM\r\n";
	$vcal .= "TRIGGER:-PT15M\r\n";
	$vcal .= "ACTION:DISPLAY\r\n";
	$vcal .= "DESCRIPTION:Reminder\r\n";
	$vcal .= "END:VALARM\r\n";
	$vcal .= "END:VEVENT\r\n";
	$vcal .= "END:VCALENDAR\r\n";
 
	$headers = "From: $from\r\nReply-To: $from"; 
	$headers .= "\r\nMIME-version: 1.0\r\nContent-Type: text/calendar; name=calendar.ics; method=REQUEST; charset=\"iso-8859-1\"";
	$headers .= "\r\nContent-Transfer-Encoding: 7bit\r\nX-Mailer: Microsoft Office Outlook 12.0"; 
 
	return @mail($to, $subject . " " . $summary . " / " . $resources, $vcal, $headers);
}

cheers.
Sebastian

10 thoughts on “ Submit Outlook Calendar Invitations with PHP ”

  1. i am new to the PHP and i used same code to send an outlook MR but i am not getting any MR into my inbox.

    I just copy your code and deployed into xampp server. we have to do any other settings?

    Regards,
    Harish

  2. hi, i didnt get this can please explain me

    $from = ORGANISATIONREPLYMAIL;
    $dtstart = date(‚Ymd‘,$tsStart).’T‘.date(‚His‘,$tsStart);
    $dtend = date(‚Ymd‘,$tsEnd).’T‘.date(‚His‘,$tsEnd);
    $loc = $location;

    $vcal = „BEGIN:VCALENDAR\r\n“;
    $vcal .= „VERSION:2.0\r\n“;
    $vcal .= „PRODID:-//nonstatics.com//OrgCalendarWebTool//EN\r\n“;
    $vcal .= „METHOD:REQUEST\r\n“;
    $vcal .= „BEGIN:VEVENT\r\n“;
    $vcal .= „ORGANIZER;CN=\““.ORGANISATIONNAME.“ („.$_SESSION[‚username‘].“)“.“\“:mailto:“.ORGANISATIONREPLYMAIL.“\r\n“;
    $vcal .= „UID:“.date(‚Ymd‘).’T‘.date(‚His‘).“-„.rand().“-nonstatics.com\r\n“;

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert