Create and send outlook meeting calendar event using php

In this article I am going to explain How to Create and send outlook meeting calendar event using php.
Before getting started with the process, lets analyse the terms used in the article.
Outlook Meetings: When you  schedule a meeting in outlook calendar, it actively involve the people that you book the meeting with, along with their calendars.
Outlook Events: An event is an appointment that is scheduled for more than 24 hours. So, if you take an appointment and set it to end two days from now it becomes an event instead.

You can create appointments & meeting using outlook  interface easily but suppose you want to automate the process for visitors of your website then you have to write  a mailer code with appointment feature for this.
php mailer scripts are available easily or you can write it without any hassle but for appointment, you have to implement some mime and header in scripts.
You can find the php code to create and send outlook meeting calendar event below.

Create and send outlook meeting calendar event using php

<?php

$from_name = "Your Name";
$from_address = "youremail@yourdomain.com";
$to_name = "Receiver Name"
$to_address = "receiveremail@yourdomain.com";
$startTime = "04/15/2020 12:00:00";
$endTime = "04/15/2020 12:30:00";
$subject = "Reminder for event";
$description = "eminder for event";
$location = "Your Location";
$domain = 'yourdomain.com';

//Create Email Headers
$mime_boundary = "----Meeting Booking----".MD5(TIME());

$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 = "--$mime_boundary\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "<html>\n";
$message .= "<body>\n";

$message .= 'Demo Message';

$message .= "</body>\n";
$message .= "</html>\n";
$message .= "--$mime_boundary\r\n";

//Event setting
$ical = 'BEGIN:VCALENDAR' . "\r\n" .
'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VTIMEZONE' . "\r\n" .
'TZID:Eastern Time' . "\r\n" .
'BEGIN:STANDARD' . "\r\n" .
'DTSTART:20091101T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" .
'TZOFFSETFROM:-0400' . "\r\n" .
'TZOFFSETTO:-0500' . "\r\n" .
'TZNAME:EST' . "\r\n" .
'END:STANDARD' . "\r\n" .
'BEGIN:DAYLIGHT' . "\r\n" .
'DTSTART:20090301T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" .
'TZOFFSETFROM:-0500' . "\r\n" .
'TZOFFSETTO:-0400' . "\r\n" .
'TZNAME:EDST' . "\r\n" .
'END:DAYLIGHT' . "\r\n" .
'END:VTIMEZONE' . "\r\n" .
'BEGIN:VEVENT' . "\r\n" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."@".$domain."\r\n" .
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
'DTSTART;TZID="Pacific Daylight":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
'DTEND;TZID="Pacific Daylight":'.date("Ymd\THis", strtotime($endTime)). "\r\n" .
'TRANSP:OPAQUE'. "\r\n" .
'SEQUENCE:1'. "\r\n" .
'SUMMARY:' . $subject . "\r\n" .
'LOCATION:' . $location . "\r\n" .
'CLASS:PUBLIC'. "\r\n" .
'PRIORITY:5'. "\r\n" .
'BEGIN:VALARM' . "\r\n" .
'TRIGGER:-PT15M' . "\r\n" .
'ACTION:DISPLAY' . "\r\n" .
'DESCRIPTION:Reminder' . "\r\n" .
'END:VALARM' . "\r\n" .
'END:VEVENT'. "\r\n" .
'END:VCALENDAR'. "\r\n";
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST'."\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $ical;

mail($to_address, $subject, $message, $headers);
?>

This code is pretty self explanatory but if you are new to PHP,  you can find the explanation of php mailer code here.

Change the variables value accordingly and leave the $ical variable value as it is and use the code to send the outlook calendar event.

Watch the video for live demo, If you have any question or query,  ask it on our Ask Question page.
Check the completed source code on GitHub.