Adding a Calendar Event to Outlook or iCal
Looking to add the ability to create Calendar events to your website? I wrote up a quick php script that will allow you to do just that. I am not including the form layout, as there are several out there that force a datetime format when the user clicks on the box. Having said that, let's hop right in
First you'll want to specify that the .ics event gets created inline. So you can call this external script without forcing the user to leave their current page
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=alert.ics");
Next, let's fetch the posted variables from your form. You can create these in separate fields or just call it all at once and split it up on the php side. How you want to do that is really up to you
$year = $_POST['year'];
$month = $_POST['month'];
$day = $_POST['day'];
$time = $_POST['time'] . '00';
$summary = $_POST['summary'];
Next, let's go ahead and build that calendar event folks!
echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "PRODID:-//YourSite//NONSGML YourSite//EN\n";
echo "METHOD:PUBLISH\n"; // required by Outlook
echo "BEGIN:VEVENT\n";
echo "UID:".date('Ymd').'T'.date('His')."-".rand()."-yoursite.com\n"; // required by Outlook
echo "DTSTAMP:".date('Ymd').'T'.date('His')."\n"; // required by Outlook
echo "DTSTART:$year"."$month"."$day"."T"."$time\n"; //20120824T093200 (Datetime format required)
echo "SUMMARY:$summary\n";
echo "DESCRIPTION: this is just a test\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";
And there you have it. Quick, easy and no extra libraries required