Probably everybody is familiar with the calendar event invite features?
If you use Microsoft Windows (with Outlook) or Mac OSX (with iCal) or just a basic browser with a GMail account and you use the calendar functionality, you would have realized, that every time you get invited or invite someone to an event, you get a basic email, that adds the recipient to the calendar event.
According to the protocol RFC and the Wikipedia entry, the iCalendar and vCalendar seems really similar, so we can use the common items to create a meeting invite.
Let’s pick a basic sample so that we can run some tests on:
DESCRIPTION:Complete event on http://www.sample.com/get_event.php?id=12345678
Now, how do we send this event?
It is pretty simple.
We need a specific set of headers on the email, and the content of the email has to be the structured meeting code itself.
(No, it is not an attachment, also if you see an attached file!)
The headers are exactly as below:
$headers = "From: Enrico <email@example.com>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/calendar; method=REQUEST;\n";
$headers .= ' charset="UTF-8"';
$headers .= "\n";
$headers .= "Content-Transfer-Encoding: 7bit";
NB: be REALLY careful with the spacing. Apparently calendars are really really fragile, and if you only remove a space, it will result on Outlook removing the buttons at the top of the email itself, where you can accept/reject the meeting, or/and even the attendees will disappear from the list!
It really caused me a lot of headache!
Now we can actually send the above calendar invite, as body of the email, structuring the meeting as per above sample, inside the content of $message variable.
$subject = "Meeting Subject";
$subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8');
mail("firstname.lastname@example.org", $subject, $message, $headers);
Of course you will have to send an email for each attendee.
There you go, you just invited your attendee to meeting with id ‘12345678’!
As simple as that!