1

I'm trying to send a calendar invite to Gmail using sendgrid and swiftmailer. This is my entire code:

<html>
<head>
    <title>PHP Test</title>
</head>
<body>

<?php

require_once('path/to/lib/swift_required.php');
require('path/to/smtpapi-php.php');

$transport = \Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
$transport->setUsername('uname');
$transport->setPassword('pass');

$mailer = \Swift_Mailer::newInstance($transport);

$ical="BEGIN:VCALENDAR\r\n
PRODID:-//Microsoft Corporation//Outlook 14.0 MIMEDIR//EN\r\n
VERSION:2.0\r\n
METHOD:REQUEST\r\n
Content-Type: text/calendar; charset="utf-8"; name=“invite.ics"; method=REQUEST'."\r\n";
Content-Disposition: inline; filename=“invite.ics"'."\r\n;
BEGIN:VEVENT\r\n
ATTENDEE;CN=aaa@aaa.com;RSVP=
    TRUE:mailto:aaa@aaa.com\r\n
CLASS:PUBLIC\r\n
CREATED:20110803T133418Z\r\n
DTEND:20150429T035959Z\r\n
DTSTAMP:20110803T095605Z\r\n
DTSTART:$20150429T170000Z\r\n
LAST-MODIFIED:20110803T133418Z\r\n
ORGANIZER;CN=\”bbb\”:mailto:
 bbb@bbb.com\r\n
PRIORITY:5\r\n
SEQUENCE:0\r\n
SUMMARY;LANGUAGE=ro:New Event\r\n
TRANSP:OPAQUE\r\n
UID:".MD5(TIME())."-85d2-69b00dea0ad4\r\n
X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE\r\n
X-MICROSOFT-CDO-IMPORTANCE:1\r\n
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\n
X-MICROSOFT-DISALLOW-COUNTER:FALSE\r\n
X-MS-OLK-AUTOSTARTCHECK:FALSE\r\n
X-MS-OLK-CONFTYPE:0\r\n
BEGIN:VALARM\r\n
TRIGGER:-PT15M\r\n
ACTION:DISPLAY\r\n
DESCRIPTION:Reminder\r\n
END:VALARM\r\n
END:VEVENT\r\n
END:VCALENDAR\r\n";

$attachment = Swift_Attachment::newInstance()
    ->setFilename("invite.ics")
    ->setContentType('multipart/alternative;charset=UTF-8;name="invite.ics";method=REQUEST')
    ->setBody($ical)
    ->setDisposition('inline;filename=invite.ics');


$message = new \Swift_Message();
$message->setTo(array('aaa@aaa.com'));
$message->setFrom('bbb@bbb.co');
$message->setSubject('Hello');
$message->attach($attachment);

try {
    $response = $mailer->send($message);
    print_r($response);
} catch(\Swift_TransportException $e) {
    print_r('Bad username / password');
}

?>

</body>
</html>

What is happening is that it is sending the email with the ics attachment but gmail and outlook are not recognizing that its a calendar invite. Can you please help me?

I've used this link as reference: ics file not recognized by outlook

Community
  • 1
  • 1
90abyss
  • 7,037
  • 19
  • 63
  • 94

1 Answers1

3

Some problems I see immediately:

  1. You are not specifying a text/calendar content type.
  2. You are using the wrong quotes in the content-type header and various other places. ( instead of ").
  3. You are embedding triple-newlines (\n\r\n) because you have both a real newline and a \r\n.

This might not fix it, but it's a starting point. I would recommend taking a good look at the source of the email you are sending, and compare it to a correctly working iMip invite. I'd assume it's not the only problem.

Evert
  • 93,428
  • 18
  • 118
  • 189