PHP generate calendar file (ics)

I am working with some Event management system recently.
The system requirement need to send out the confirmation to those registrants with a calendar ics attachment.
For this, I need to make my application to generate the ics file and attach it inside the email notification.

Below is the source to generate the ics file.

<?php
//This is the most important coding.
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=filename.ics");
echo "BEGIN:VCALENDAR\n";
echo "PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN\n";
echo "VERSION:2.0\n";
echo "METHOD:PUBLISH\n";
echo "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n";
echo "BEGIN:VEVENT\n";
echo "CLASS:PUBLIC\n";
echo "CREATED:20091109T101015Z\n";
echo "DESCRIPTION:How 2 Guru Event\\n\\n\\nEvent Page\\n\\nhttp://www.myhow2guru.com\n";
echo "DTEND:20091208T040000Z\n";
echo "DTSTAMP:20091109T093305Z\n";
echo "DTSTART:20091208T003000Z\n";
echo "LAST-MODIFIED:20091109T101015Z\n";
echo "LOCATION:Anywhere have internet\n";
echo "PRIORITY:5\n";
echo "SEQUENCE:0\n";
echo "SUMMARY;LANGUAGE=en-us:How2Guru Event\n";
echo "TRANSP:OPAQUE\n";
echo "UID:040000008200E00074C5B7101A82E008000000008062306C6261CA01000000000000000\n";
echo "X-MICROSOFT-CDO-BUSYSTATUS:BUSY\n";
echo "X-MICROSOFT-CDO-IMPORTANCE:1\n";
echo "X-MICROSOFT-DISALLOW-COUNTER:FALSE\n";
echo "X-MS-OLK-ALLOWEXTERNCHECK:TRUE\n";
echo "X-MS-OLK-AUTOFILLLOCATION:FALSE\n";
echo "X-MS-OLK-CONFTYPE:0\n";
//Here is to set the reminder for the event.
echo "BEGIN:VALARM\n";
echo "TRIGGER:-PT1440M\n";
echo "ACTION:DISPLAY\n";
echo "DESCRIPTION:Reminder\n";
echo "END:VALARM\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";
?>

I tested above script, it working fine with the Microsoft Outlook 2007.
Cheers~~!

9 Comments to “PHP generate calendar file (ics)”

  1. sandeep 8 January 2010 at 6:56 pm #

    Thank you the post has given me a nice insight on the topic

  2. […] Click here for this Tutorial! […]

  3. manjunatha 26 April 2010 at 11:40 pm #

    Can we directly integrate the downloaded file to outlook .. Waiting for the reply…

  4. Bruce 20 May 2010 at 12:50 am #

    […] Click here for this Tutorial! […]

  5. h2Guru 20 May 2010 at 6:46 pm #

    Hi manjunatha,

    I think it is not possible at the moment.
    Will try to check it out and get you inform if any.

  6. barno 27 May 2011 at 2:22 am #

    Hi, how can we use this code on a wordpress post so that when you click the link it will download the .ics file, but not popup automatically on page load? thanks for your help!

  7. sahil 9 September 2011 at 1:11 am #

    good work,
    atleast i got the idea to go about, nice work

  8. Jesse 5 March 2012 at 1:15 am #

    Just link to the php file that will generate the ics; on your page, create a link that calls the above php script.

    You can also pass the variables to it in the url and have the event details created on the fly, if you need it to be dynamic.

  9. […] Source open source code, PHP […]


Leave a Reply