Search code examples
phpgmailphpmailericalendar

ICS file in Gmail (PhpMailer)


I'm trying to send an .ics file via PhpMailer to make the user able to import it easily.

This works fine when sending it to Outlook, however Gmail does not recognize the file and thus gives no option to import it into a google calendar.

My ics file looks like this:

BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 14.0 MIMEDIR//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Romance Standard Time
BEGIN:STANDARD
DTSTART:16011028T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
END:STANDARD
DTSTART:16010325T020000
BEGIN:DAYLIGHT
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
CLASS:PUBLIC
DESCRIPTION:
DTEND;TZID="Romance Standard Time":20130815T154000
DTSTAMP:20130814T094035Z
DTSTART;TZID="Romance Standard Time":20130815T144000
SUMMARY:Your appointment
LOCATION:1000 Brussels
END:VEVENT
END:VCALENDAR

My php code then looks like this:

$mail->AddAttachment('../linkToIcs.ics');

The file gets attached fine, but is not recognized by Gmail. I then tried adding it as a string attachment

if (pathinfo($attachment, PATHINFO_EXTENSION) == 'ics') {
    $contents = file_get_contents($attachment);
    $mail->AddStringAttachment(
        $contents,
        pathinfo($attachment, PATHINFO_BASENAME),
        '7bit',
        'text/calendar'
    );
}

which added it correctly as an attachment, but is again not recognized as an 'importable' calendar event in Gmail.

I should also note that there is an HTML body in the same email.

Any explanation as to why this isn't working would be great.


Solution

  • Forgot to answer..

    I fixed it by removing the TZID after DTEND and DTSTART apparently this is not recognized by Gmail.