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.
I had to write an invitation tool that was cross compatible between different platforms and integrated with SugarCRM for a customer of InsightfulCRM (Australian SugarCRM Gold Partner) where I work.
I started from some samples, and by reading the RFC of the protocol and the iCalendar Wikipedia entry.
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:
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20100616T080000Z
DTEND:20100616T090000Z
DTSTAMP:20100616T075116Z
ORGANIZER;CN=Enrico Simonetti:mailto:enrico@test.com
UID:12345678
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Sample:mailto:sample@test.com
DESCRIPTION:Complete event on http://www.sample.com/get_event.php?id=12345678
LOCATION: Sydney
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Test iCalendar
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
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 <enrico@test.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("sample@test.com", $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!

Wow… you make it sound so simple. I’m sure there was plenty more blood, sweat and tears to get to the end result, right. But, yes, it’s now done and it’s a cool extra piece of functionality for SugarCRM!
Hello there,
I just tried your solution only i can’t get it to work.
I am currently using SugarCRM 6.1.3 on windows 7.
I created a logic hook before_save, in Meetings module.
The hook calls a file(sendEmailMeeting.php)which contains the following code:
bean->location;
$headers = “From: SugarCRM \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\n”;
$subject = $this->bean->name;
$subject = html_entity_decode($subject, ENT_QUOTES, ‘UTF-8′);
$message= “BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20110616T080000Z
DTEND:20110616T090000Z
DTSTAMP:20110616T075116Z
ORGANIZER;CN=SugarCRM:mailto:some.body@mycomp.com
UID:1
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Sample:mailto:sample@test.com
DESCRIPTION:Complete event on http://www.sample.com/get_event.php?id=1
LOCATION: $location
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Test iCalendar
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR”;
mail(“mytarget@somecompany.com”, $subject, $message, $headers);
}
}
?>
Can you please tell me what is it I am missing??
Thanks a lot in advance.
Cheers
Try removing the final \n from $headers .= “Content-Transfer-Encoding: 7bit\n”;
And also, each string has to be split using ‘folding’.
You can read more about this here: http://tools.ietf.org/rfc/rfc5545.txt
Great tutorial! I’ve noticed that it didn’t worked properly with Mozilla Thunderbird. I’ve modified the headers by looking at the source of a ‘real’ invite, and I came up with this and it works fine:
$headers = “Return-Path: \n”;
$headers .= “From: My Name \n”;
$headers .= “MIME-Version: 1.0\n”;
$headers .= “Content-class: urn:content-classes:calendarmessage\n”;
$headers .= “Content-Type: text/calendar; method=REQUEST; component=VEVENT; name=meeting.ics;\n”;
$headers .= ‘ charset=”UTF-8″‘;
$headers .= “\n”;
$headers .= “Content-Transfer-Encoding: 7bit”;
I’ve noticed that the my post isn’t getting posted correctly. After Return-Path and From: My Name, add a space and then the requesters’ e-mail address between
Thanks for the feedback Roy!
I’m glad you liked the article!
Tested your example on microsoft outlook. it does not show calendar… any suggestions how to solve it?
I would suggest you to double check the exact number of spaces and tabs on the invite’s content.
If still does not work, try viewing the source of a real invite generated with Outlook and check your code against it…