2

The following code sends ical invites flawlessly to our internal mail system. However, in gmail I only see a meeting.ics file attachment. I do not see the block that asks me to RSVP. What am I missing?

require_once 'swiftmailer/lib/swift_required.php';

$messageObject = Swift_Message::newInstance();
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
  ->setUsername('me@gmail.com')
  ->setPassword('passwd');

$messageObject->setContentType("multipart/alternative");
$messageObject->addPart("Email message body goes here", "text/html");

$messageObject->setSubject("Subject line goes here")
  ->setFrom('support@me.com', 'ME');

$messageObject->setTo(array('me@gmail.com'));

$ics_content = file_get_contents("cal.ics");
$ics_attachment = Swift_Attachment::newInstance()
  ->setBody(trim($ics_content))
  ->setEncoder(Swift_Encoding::get7BitEncoding());
$headers = $ics_attachment->getHeaders();
$content_type_header = $headers->get("Content-Type");
$content_type_header->setValue("text/calendar");
$content_type_header->setParameters(array(
  'charset' => 'UTF-8',
  'method' => 'REQUEST'
));
$headers->remove('Content-Disposition');

$messageObject->attach($ics_attachment);

$mailObject = Swift_Mailer::newInstance($transport);
$mailObject->send($messageObject);

Here's `cal.ics' file:

BEGIN:VCALENDAR
PRODID:-//support@me.com//support@me.com//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20150929T133000Z
DTEND:20150929T190000Z
DTSTAMP:20150911T210204Z
ORGANIZER;CN=support@me.com:MAILTO:ME
UID:NRT Sales Pro
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE;CN=support@me.com;X-NUM-GUESTS=0:NRT Sales Pro
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=NRT Sales Pro;X-NUM-GUESTS=0:NRT Sales Pro
CREATED:20150911T210204Z
LAST-MODIFIED:20150911T210204Z
LOCATION:Dix Hills, NY Education Center | 1206 E Jericho Tpke, Huntington NY 11743
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Discover the Difference
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
Rayhan Muktader
  • 2,038
  • 2
  • 15
  • 32

1 Answers1

1

About your icalendar data, none of your ORGANIZER or ATTENDEE property are valid. Each of them should have a valid mailto: uri as value (with at least one of them corresponding to the gmail account if you are trying to accept from gmail).

Then you need to be really careful with the MIME Structure of the email you are sending. See Multipart email with text and calendar: Outlook doesn't recognize ics

Community
  • 1
  • 1
Arnaud Quillaud
  • 4,420
  • 1
  • 12
  • 8