PHPMailer
PHPMailer copied to clipboard
iCalendar invite is not showing RSVP buttons in email clients
I'm using PHPMailer to send email. My ics content is:
BEGIN:VCALENDAR
METHOD:REQUEST
VERSION:2.0
PRODID:-//FooBar//FooBar Calendar//EN
BEGIN:VEVENT
UID:8f5a0777-bf6d-17d2-f14a-52e7feedf810
ORGANIZER;CN=Foo:[email protected]
DTSTART:20140130T191500Z
DTEND:20140130T194500Z
DTSTAMP:20140129T144300Z
SUMMARY:Foo Bar 11
DESCRIPTION:
END:VEVENT
END:VCALENDAR
For some reason I don't see the expected RSVP buttons in any email clients. Both Gmail and Mac Mail simply include the ics as a file attachment, I assume as a fallback. So there must be something wrong. I have not tried Outlook, but I don't see any reason why it would be different in a third client. The contents of an email being sent are below. Can you see anything that looks incorrect? Thank you.
Return-Path: REDACTED
Received: REDACTED
Date: Wed, 29 Jan 2014 09:43:18 -0500
Return-Path: REDACTED
To: REDACTED
From: REDACTED
Reply-To: REDACTED
Subject: Meeting - Foo Bar 11
Message-ID: <7004961cd9df04181047296f98260834@localhost>
X-Priority: 3
X-Mailer: PHPMailer 5.2.7 (https://github.com/PHPMailer/PHPMailer/)
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="b1_7004961cd9df04181047296f98260834"
Content-Transfer-Encoding: base64
--b1_7004961cd9df04181047296f98260834
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
VG86IEZvbyBCYXINCg0KDQpBZG1pbmlzdHJhdG9yIGhhcyBpbnZpdGVkIHlvdSB0byBhIE1lZXRpbmcNCg0KDQpTdWJqZWN0OiBGb28gQmFyIDExDQoNClN0YXJ0IERhdGU6IDAxLzMwLzIwMTQgMDI6MTVwbSBFU1QoLTA1OjAwKQ0KDQpFbmQgRGF0ZTogMDEvMzAvMjAxNCAwMjo0NXBtIEVTVCgtMDU6MDApDQoNCg0KRGVzY3JpcHRpb246IA0KDQoNCkFjY2VwdCB0aGlzIG1lZXRpbmc6DQoNCmh0dHA6Ly9sb2NhbGhvc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WJmNmQtMTdkMi1mMTRhLTUyZTdmZWVkZjgxMA0KT1JHQU5JWkVSO0NOPUZvbzpmb29AYmFyLmNvbQ0KRFRTVEFSVDoyMDE0MDEzMFQxOTE1MDBaDQpEVEVORDoyMDE0MDEzMFQxOTQ1MDBaDQpEVFNUQU1QOjIwMTQwMTI5VDE0NDMwMFoNClNVTU1BUlk6Rm9vIEJhciAxMQ0KREVTQ1JJUFRJT046DQpFTkQ6VkVWRU5UDQpFTkQ6VkNBTEVOREFSDQo=
--b1_7004961cd9df04181047296f98260834--
P.S. Sorry about it being base64 encoded. I wanted to show a true representation of the email instead of changing it any way that may skew the results. I just use http://www.base64decode.org/ to decode the contents.
P.P.S. The base64 contents show as one string, but the email is sent with a max of 1000 characters per line. I just needed to remove some sensitive information, so I had to re-encode those parts, which removed the breaks.
The attachment is all that the iCal/ICS format defines. In google calendar invitations their MIME structure is exactly the same in PHPMailer, but the HTML message body contains links back to google calendar that fulfil the yes/no/maybe functions. PHPMailer doesn't know anything about the system the calendar relates to, so it's up to you to provide that functionality. If individual email clients have support for ics attachment types (I've not seen mail do this, but then I've only every received invitations from gcal) then it could possibly do something with it.
I've found some references (on stack overflow) to exactly what things like Outlook are looking for and I've been trying them out in a local version but I've not managed to make anything special happen. I also found an ICS validator that highlighted a few problems with the bundled ICS generator class.
I've realised that there isn't a code example for using calendar events, but there is a test case that's easily adapted.
Thanks for the response. I got things sorted out. I was missing mailto:
in the ORGANIZER
property value. It should have been ORGANIZER;CN=Foo:mailto:[email protected]
. And the biggest thing was that I needed to force the use of CRLF for line endings. The ATTENDEE
property is also required, but that didn't seem to be a requirement to get Outlook and Mac Mail to render the RSVP buttons. My final iCal metadata looked like:
VERSION:2.0
BEGIN:VCALENDAR
PRODID:-//FooBar//FooBar Calendar//EN
METHOD:REQUEST
BEGIN:VEVENT
UID:8f5a0777-bf6d-17d2-f14a-52e7feedf810
ORGANIZER;CN=Foo:mailto:[email protected]
DTSTART:20140130T191500Z
DTEND:20140130T194500Z
DTSTAMP:20140129T144300Z
SUMMARY:Foo Bar
DESCRIPTION:
END:VEVENT
END:VCALENDAR
For my situation, I was unable to use the bundled EasyPeasyICS, but I did look at the iCal unit test to see how to set things up. And I probably used the same validators as you. The validators don't seem to catch everything though; the line endings are an example of something they missed. And as you mentioned, EasyPeasyICS doesn't seem match up with RFC 5546. As ICS support is expanded, it might be worth considering replacing EasyPeasyICS with something that implements the spec.
Some other things of interest that I learned through this exercise:
- Outlook and Mac Mail only show their RSVP buttons if you add the ICS content in the way that PHPMailer has implemented it. They will not show RSVP buttons if the ICS file is simply attached.
- Gmail only shows its "Add to calendar" wrapper (its equivalent to RSVP buttons) if the ICS file is attached. The event is only added to your Google Calendar if the ICS file is attached.
- When sending an invite from Outlook, the ICS content is added the way PHPMailer has implemented it. Thus, Outlook and Mac Mail will recognize it but Gmail will not.
- When sending an invite from Mac Mail/iCal, the ICS file is attached. Thus, Gmail will recognize it but Outlook and Mac Mail will not.
- When sending an invite from Gmail/Google Calendar, the ICS file is attached AND the ICS content is added the way PHPMailer has implemented it. Thus, all three clients will recognize it.
That's some great research, thanks for the effort! I've had emails with the author of EasyPeasyICS and he's happy for me to take it over, so we're free to do whatever we want with it.
PHPMailer should be defaulting to CRLF line breaks; I don't think it should allow you to switch since none of the RFCs allow it. Attaching both formats seems sensible.
In my experiments I needed to alter various things in PHPMailer, in particular I needed to be able to provide a content-disposition header for the ICS part (from what I read, some clients require it to be marked as 'inline') and that required extending the getBoundary method.
I'll push my changes to my own fork later, see what you think. It would be good if you could wrap up your changes in a pull request.
As far as the line endings go, the issue is with the ICS metadata. Since EasyPeasyICS is just wrapping a long string in EasyPeasyICS::render()
the line endings are at the mercy of the OS on which the application is running (or whatever PHP_EOL
is). If your system uses \n
, then those bytes will be encoded by PHPMailer. If your encoding is base64
then those lines are not fixed by PHPMailer::fixEOL
. Only the lines at the end of each chunk would be fixed. That's just one detail to pay attention to.
I didn't do any patching of PHPMailer or EasyPeasyICS -- I only made modifications in my own code that was building the ICS content to avoid changing a third-party library -- but I can certainly whip up a PR to address some of the things I learned. Is the plan to put EasyPeasyICS in its own repo and make it a dependency or to just start changing it from within the PHPMailer repo? I read some of your comments about using dependency injection for the SMTP class to allow for custom implementations, so this could be another example of the same concern.
I did attempt a patch of PHPMailer for adding both the attachment and the ICS message part. However, I never got it to work in Gmail and I had to give up for the time being. So it would be premature for me to try to open a PR for that. But I'll share the patch I have, as well as the email sources from PHPMailer and Gmail that I've been diff-ing to help me chase down the root cause. Maybe one of us, or someone else in the community, will be able to figure it out from there.
Hello, i've a problem sending ical through PHPMailer to a gmail account, the ical file is send as an attachment, and for some reazon gmail don't add it to the calendar, if the same file is sent to an account and opened with Outlook, there is no problem at all. Could you help me with this matter?
Here is an example of the ical file created with icalcreator:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Skytel.com//NONSGML kigkonsult.se iCalcreator 2.20.2//
CALSCALE:GREGORIAN
METHOD:REQUEST
X-WR-CALNAME:Entrevista
X-WR-CALDESC:Entrevista con postulante para Programador
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:20140522T163044Z
ATTENDEE;RSVP=TRUE;CN= EVERTON DANIEL CAZAL KONTOVSKI;X-NUM-GUESTS=0:MAILTO
:[email protected]
DESCRIPTION:El día 23/05/2014 a las 16:30 hs tiene entrevista con la seño
ra Alicia Romina García Olmedo por la postulación al puesto de Programador
.\n
DTSTART:20140523T163000
DURATION:PT0H30M0S
LOCATION:Sala de Reuniones
ORGANIZER;CN= EVERTON DANIEL CAZAL KONTOVSKI:MAILTO:[email protected]
.py
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Entrevista con postulante para Programador
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
Many thanks for any help you could bringme.
If you read the rest of this thread, you'll see the problem is that the ICS file needs to be added both as an attachment and as a member of a multipart/alternative MIME structure to satisfy both gmail and outlook. The problem in PHPMailer is that we're heading for an exponential explosion in the number of possible combinations of MIME structures, and because PHPMailer only has preset options, it's getting out of hand. I did start having a look at this, but it's just really difficult to handle it in a sane way with the current MIME structure, and a complete overhaul of that is beyond the scope of this ticket. Something you could do is build the message with Zend or Pear MIME classes and then just use PHPMailer to send it.
Is there an example of how to actually send an invite using phpmailer? I'm guessing on the format and order of things ...
$invite = new EasyPeasyICS();
$invite->addEvent('06-06-2014 08:00:00','06-06-2014 17:00:00',"TEST","TEST","");
$mail = new PHPMailer();
$mail->isSMTP();
$mail->IsHTML(false);
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'spo.test.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->setFrom('[email protected]', 'OBrien, David');
$mail->addAddress('[email protected]', 'OBrien, David');
$mail->Subject = "TEST CALENDAR";
$mail->Body = $invite;
$mail->AltBody = "TEST CALENDAR";
$mail->Ical = $invite;
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
...
PHPMailer expects a string containing the ICS data, so set it like this when using EasyPeasyICS:
$mail->Ical = $invite->render();
Hello, I have the same problem than Bladezal , the RSVP buttons don't appear for me on Gmail however I include the ical in the multipart/alternative and as a attachment as you say and it works only on Outlook. I would appreciate if you could help me with this, here my headers and the Ical:
Content-Type: multipart/mixed; boundary="b1_48fb71c31b1b47230328819926821af0" Content-Transfer-Encoding: 8bit --b1_48fb71c31b1b47230328819926821af0
Content-Type: multipart/alternative; boundary="b2_48fb71c31b1b47230328819926821af0" --b2_48fb71c31b1b47230328819926821af0 Content-Type: text/plain; charset=us-ascii Test
--b2_48fb71c31b1b47230328819926821af0
Content-Type: text/calendar; method=REQUEST; charset=UTF-8 Content-Transfer-Encoding: 8bit BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN METHOD:REQUEST BEGIN:VEVENT ORGANIZER;CN='Bob Miller':MAILTO:[email protected] ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=Bob Miller;X-NUM-GUESTS=0:mailto:[email protected] DTSTART:20141031T170000Z DTEND:20141031T180000Z LOCATION: Online Seminar UID:[email protected] DTSTAMP:20141031T170000Z DESCRIPTION:invitation to seminar SUMMARY:invitation to seminar SEQUENCE:0 STATUS:CONFIRMED END:VEVENT END:VCALENDAR
--b2_48fb71c31b1b47230328819926821af0
Content-Type: text/html; charset=us-ascii
Host: smtp.gmail.com
Attachments:
- Name: invite.ics, Encoding: base64, Type: text/calendar
--b2_48fb71c31b1b47230328819926821af0--
--b1_48fb71c31b1b47230328819926821af0
Content-Type: text/calendar; name="invite.ics" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=invite.ics QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOi0vL01pY3Jvc29mdCBDb3Jwb3JhdGlvbi8vT3V0bG9vayAxMS4wIE1JTUVESVIvL0VODQpNRVRIT0Q6UkVRVUVTVA0KQkVHSU46VkVWRU5UDQpPUkdBTklaRVI7Q049J0JvYiBNaWxsZXInOk1BSUxUTzpibWlsbGVyMzRAZ21haWwuY29tDQpBVFRFTkRFRTtDVVRZUEU9SU5ESVZJRFVBTDtST0xFPVJFUS1QQVJUSUNJUEFOVDtQQVJUU1RBVD1ORUVEUy1BQ1RJT047UlNWUD1UUlVFO0NOPUJvYiBNaWxsZXI7WC1OVU0tR1VFU1RTPTA6bWFpbHRvOmFkcmlhbnNlZ2FAZ21haWwuY29tDQpEVFNUQVJUOjIwMTQxMDMxVDE3MDAwMFoNCkRURU5EOjIwMTQxMDMxVDE4MDAwMFoNCkxPQ0FUSU9OOiBPbmxpbmUgU2VtaW5hciANClVJRDoyNjI4NDE3YjliN2YyOWZhZjZhMDc2N2FjZjAxNGZhNkBFYXN5UGVhc3lJQ1MucGhwDQpEVFNUQU1QOjIwMTQxMDMxVDE3MDAwMFoNCkRFU0NSSVBUSU9OOmludml0YXRpb24gdG8gc2VtaW5hcg0KU1VNTUFSWTppbnZpdGF0aW9uIHRvIHNlbWluYXINClNFUVVFTkNFOjANClNUQVRVUzpDT05GSVJNRUQNCkVORDpWRVZFTlQNCkVORDpWQ0FMRU5EQVINCg==
--b1_48fb71c31b1b47230328819926821af0--
If you read back through this thread, you'll see that gmail is broken, and that fixing this in PHPMailer is not in the least bit simple, so it's not going to be fixed soon.
Hi!
Hopefully someone is still following this topic because I really need help with this RSVP button issue. The thing is that I don't want those buttons to to appear so that the event is automatically accepted (mainly in Outlook). Any ideas how to do that?
If you don't want to give them a choice, why even ask? Just add them to the event without asking.
But how do I do that? What changes do I have to make?
Thanks a lot!
I've no idea - you'd need to talk to the calendar server directly, not via email.
For me problem was that RSVP buttons not appear in Gmail although I send valid .ics file. The solution was add proper mime type to email .ics file attachement:
Content-Type: text/calendar; method=REQUEST; charset=UTF-8
I do it in laravel 5 in this way:
Mail::queue('emails.reservationInvitation', compact('guest','attendeesList','reservation', 'dayBegin', 'dayName', 'hourBegin', 'hourEnd', 'length' )
, function ($message) use ($reservation, $subject, $guest, $icalendar) {
$message->attachData($icalendar, "invite.ics", ['mime' => 'text/calendar; method=REQUEST; charset=UTF-8']);
$message->to($guest['email'])->subject($subject);
});
where $icalendar was string with content of my invite.ics file.
You can specify a MIME type when you add an attachment:
$mail->addAttachment('path/to/calendar.ics', 'calendar.ics', 'base64', 'text/calendar');
If you don't provide a MIME type manually like this, PHPMailer has a built-in list of MIME types that it associates with file extensions automatically, however ics
was missing from the list. I've now added it in the 6.0 branch.
Note that when you use PHPMailer's built-in embedded iCal support (via the Ical
property mentioned in this thread), it did already set the MIME type correctly.
If I add an Ical and attach a file at the same time, the Ical info is not sent with the mail. If I remove the attachment, the mail is sent with the Ical info (however not recognized by Outlook/Mail..).
My PHP `$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/ical.ics", "wb"); fwrite($fp, $this->renderIcs($events, false)); fclose($fp);
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->isSMTP();
$mail->IsHTML(false);
$mail->Host = env('MAIL_HOST');
$mail->Port = env('MAIL_PORT');
$mail->SMTPAuth = true;
$mail->Username = env('MAIL_USERNAME');
$mail->Password = env('MAIL_PASSWORD');
$mail->setFrom($email, $name);
$mail->addAddress($email, $name);
$mail->Subject = trans('emails.reservation.email_subject', ['reservation_title' => strip_tags($reservation->title)]);
$mail->Body = "test";
$mail->AltBody = "test";
$mail->addAttachment($_SERVER['DOCUMENT_ROOT'] . "/ical.ics", 'calendar.ics', 'base64', 'text/calendar');
$mail->Ical = $this->renderIcs($events, false);
$mail->Send();
}`
Gives me the following mail:
Date: Tue, 1 Aug 2017 14:44:29 +0000 To: xxx From: xxx Subject: Calendar Invite: asd Message-ID: 7401f051c441e65793fba6425f30fccd@laravel X-Mailer: PHPMailer 5.2.24 (https://github.com/PHPMailer/PHPMailer) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="b1_7401f051c441e65793fba6425f30fccd" Content-Transfer-Encoding: 8bit
This is a multi-part message in MIME format.
--b1_7401f051c441e65793fba6425f30fccd Content-Type: multipart/alternative; boundary="b2_7401f051c441e65793fba6425f30fccd"
--b2_7401f051c441e65793fba6425f30fccd Content-Type: text/plain; charset=us-ascii
test
--b2_7401f051c441e65793fba6425f30fccd Content-Type: text/html; charset=us-ascii
test
--b2_7401f051c441e65793fba6425f30fccd--
--b1_7401f051c441e65793fba6425f30fccd Content-Type: text/calendar; name="calendar.ics" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=calendar.ics
VkVSU0lPTjoyLjANCkJFR0lOOlZDQUxFTkRBUg0KUFJPRElEOi0vL2hhY2tzdy9oYW5kY2FsLy9OT05TR01MIHYxLjAvL0VODQpNRVRIT0Q6UkVRVUVTVA0KQkVHSU46VkVWRU5UDQpVSUQ6eHh4LTEyMy14eHgNCk9SR0FOSVpFUjtDTj14eHg6bWFpbHRvOnh4eA0KRFRTVEFSVDoyMDE3MDgwMVQxMzMwMDBaDQpEVEVORDoyMDE3MDgwMVQxMzQ1MDBaDQpEVFNUQU1QOjIwMTcwODAxVDE0NDQyOVoNClNVTU1BUlk6YXNkDQpERVNDUklQVElPTjp0ZXN0DQpMT0NBVElPTjpUZXN0aW5nIHJlc291cmNlDQpTRVFVRU5DRToxDQpFTkQ6VkVWRU5UDQpFTkQ6VkNBTEVOREFS
--b1_7401f051c441e65793fba6425f30fccd--
However - removing the attached file generates this:
Date: Tue, 1 Aug 2017 14:44:17 +0000 To: xxx From: xxx Subject: Calendar Invite: asd Message-ID: 0665272647344ea75df23a6698e8a8ff@laravel X-Mailer: PHPMailer 5.2.24 (https://github.com/PHPMailer/PHPMailer) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="b1_0665272647344ea75df23a6698e8a8ff" Content-Transfer-Encoding: 8bit
This is a multi-part message in MIME format.
--b1_0665272647344ea75df23a6698e8a8ff Content-Type: text/plain; charset=us-ascii
test
--b1_0665272647344ea75df23a6698e8a8ff Content-Type: text/html; charset=us-ascii
test
--b1_0665272647344ea75df23a6698e8a8ff Content-Type: text/calendar; method=REQUEST; charset=UTF-8 Content-Transfer-Encoding: 8bit
VERSION:2.0 BEGIN:VCALENDAR PRODID:-//hacksw/handcal//NONSGML v1.0//EN METHOD:REQUEST BEGIN:VEVENT UID:xxx-123-xxx ORGANIZER;CN=xxx:mailto:xxx DTSTART:20170801T131500Z DTEND:20170801T133000Z DTSTAMP:20170801T144417Z SUMMARY:asd DESCRIPTION:test LOCATION:Testing resource SEQUENCE:1 END:VEVENT END:VCALENDAR
--b1_0665272647344ea75df23a6698e8a8ff--
What is causing this and why is it not working? Seemingly my ics file is valid and according to what i see in this thread..
Thanks for the clear description. This is down to PHPMailer's preset MIME structures - as soon as you add attachments, the message is built using the alt_attach
structure, which doesn't have Ical
support. I've just pushed a change to the 6.0 branch that does support for that, so you can at least attempt this workaround - please report your results!
Thank you, that worked. They both are included now. However - I still get no RSVP buttons in either of Mac Mail and Outlook. Any idea on what is wrong? Im able to click the attached file in Mail and get it to add it to my calendar, but the same can not be done i Outlook.
Date: Tue, 1 Aug 2017 15:42:22 +0000 To: xxx From: xxx Subject: Calendar Invite: test Message-ID: 7f2ef0f72584f4006430793cafbac142d487260b5eeac5ab78c0058e50a9076e@laravel X-Mailer: PHPMailer 6.0.0 (https://github.com/PHPMailer/PHPMailer) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="b1_7f2ef0f72584f4006430793cafbac142d487260b5eeac5ab78c0058e50a9076e" Content-Transfer-Encoding: 8bit
This is a multi-part message in MIME format. --b1_7f2ef0f72584f4006430793cafbac142d487260b5eeac5ab78c0058e50a9076e Content-Type: multipart/alternative; boundary="b2_7f2ef0f72584f4006430793cafbac142d487260b5eeac5ab78c0058e50a9076e"
--b2_7f2ef0f72584f4006430793cafbac142d487260b5eeac5ab78c0058e50a9076e Content-Type: text/plain; charset=us-ascii
test
--b2_7f2ef0f72584f4006430793cafbac142d487260b5eeac5ab78c0058e50a9076e Content-Type: text/html; charset=us-ascii
test
--b2_7f2ef0f72584f4006430793cafbac142d487260b5eeac5ab78c0058e50a9076e Content-Type: text/calendar; method=REQUEST; charset=UTF-8 Content-Transfer-Encoding: 8bit
BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN METHOD:REQUEST BEGIN:VEVENT UID:[email protected] ORGANIZER;CN=Christopher Carlsson:mailto:xxxx ATTENDEE;ROLE=REQ-PARTICIPANT;CN=Christopher Carlsson:mailto:xxxx ACTION;RSVP=TRUE;CN=Christopher Carlsson;X-NUM-GUESTS=0:mailto:xxx DTSTART:20170802T090000Z DTEND:20170802T091500Z DTSTAMP:20170801T154222Z SUMMARY:test DESCRIPTION:test LOCATION:Testing resource SEQUENCE:1 STATUS:CONFIRMED END:VEVENT END:VCALENDAR
--b2_7f2ef0f72584f4006430793cafbac142d487260b5eeac5ab78c0058e50a9076e--
--b1_7f2ef0f72584f4006430793cafbac142d487260b5eeac5ab78c0058e50a9076e Content-Type: text/calendar; name="calendar.ics" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=calendar.ics
QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOi0vL01pY3Jvc29mdCBDb3Jwb3JhdGlvbi8vT3V0bG9vayAxMS4wIE1JTUVESVIvL0VODQpNRVRIT0Q6UkVRVUVTVA0KQkVHSU46VkVWRU5UDQpVSUQ6Ym9vay04QGdldG1lZXRpby5jb20NCk9SR0FOSVpFUjtDTj1DaHJpc3RvcGhlciBDYXJsc3NvbjptYWlsdG86eHh4DQpBVFRFTkRFRTtST0xFPVJFUS1QQVJUSUNJUEFOVDtDTj1DaHJpc3RvcGhlciBDYXJsc3NvbjptYWlsdG86eHh4DQpBQ1RJT047UlNWUD1UUlVFO0NOPUNocmlzdG9waGVyIENhcmxzc29uO1gtTlVNLUdVRVNUUz0wOm1haWx0bzp4eHgNCkRUU1RBUlQ6MjAxNzA4MDJUMDkwMDAwWg0KRFRFTkQ6MjAxNzA4MDJUMDkxNTAwWg0KRFRTVEFNUDoyMDE3MDgwMVQxNTQyMjJaDQpTVU1NQVJZOnRlc3QNCkRFU0NSSVBUSU9OOnRlc3QNCkxPQ0FUSU9OOlRlc3RpbmcgcmVzb3VyY2UNClNFUVVFTkNFOjENClNUQVRVUzpDT05GSVJNRUQNCkVORDpWRVZFTlQNCkVORDpWQ0FMRU5EQVI=
--b1_7f2ef0f72584f4006430793cafbac142d487260b5eeac5ab78c0058e50a9076e--
If you do just one or the other, do the buttons you're expecting appear in either? Do you have an example message that does work correctly that we could compare it with?
Im comparing to the reply above that @adsega posted, saying he could get it to work in Outlook. Buttons don't appear with just one or the other.
I've pushed some experimental changes in 6.0-ical - the main difference is the addition of a Content-Class
header as suggested by articles here and here. Please can you give that a try?
Thank you for your continued efforts. Unfortunately it still does not work. The mail source is the following, but still no RSVP/ability to add to calendar in outlook nor Mail.
Subject: Calendar Invite: Test Message-ID: d83d69dae575b544ae866adb06fa17e53e7014bfcc12978a468b83895932fa87@laravel X-Mailer: PHPMailer 6.0.0 (https://github.com/PHPMailer/PHPMailer) MIME-Version: 1.0 Content-Class: urn:content-classes:calendarmessage Content-Type: multipart/mixed; boundary="b1_d83d69dae575b544ae866adb06fa17e53e7014bfcc12978a468b83895932fa87" Content-Transfer-Encoding: 8bit
This is a multi-part message in MIME format. --b1_d83d69dae575b544ae866adb06fa17e53e7014bfcc12978a468b83895932fa87 Content-Type: multipart/alternative; boundary="b2_d83d69dae575b544ae866adb06fa17e53e7014bfcc12978a468b83895932fa87"
--b2_d83d69dae575b544ae866adb06fa17e53e7014bfcc12978a468b83895932fa87 Content-Type: text/plain; charset=us-ascii
test
--b2_d83d69dae575b544ae866adb06fa17e53e7014bfcc12978a468b83895932fa87 Content-Type: text/html; charset=us-ascii
test
--b2_d83d69dae575b544ae866adb06fa17e53e7014bfcc12978a468b83895932fa87 Content-Type: text/calendar; method=REQUEST; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Class: urn:content-classes:calendarmessage
BEGIN:VCALENDAR METHOD:REQUEST PRODID:Microsoft Exchange Server 2010 VERSION:2.0 BEGIN:VEVENT UID:book-25@xxx ORGANIZER;CN=Christopher Carlsson:mailto:xxx ATTENDEE;ROLE=REQ-PARTICIPANT;CN=Christopher Carlsson:mailto:xxx ACTION;RSVP=TRUE;CN=Christopher Carlsson;X-NUM-GUESTS=0:mailto:xxx DTSTART:20170804T134500Z DTEND:20170804T140000Z DTSTAMP:20170804T112625Z SUMMARY:Test DESCRIPTION:test LOCATION:Testresurs SEQUENCE:1 STATUS:CONFIRMED END:VEVENT END:VCALENDAR
--b2_d83d69dae575b544ae866adb06fa17e53e7014bfcc12978a468b83895932fa87--
--b1_d83d69dae575b544ae866adb06fa17e53e7014bfcc12978a468b83895932fa87 Content-Type: text/calendar; name="calendar.ics" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=calendar.ics
QkVHSU46VkNBTEVOREFSDQpNRVRIT0Q6UkVRVUVTVA0KUFJPRElEOk1pY3Jvc29mdCBFeGNoYW5nZSBTZXJ2ZXIgMjAxMA0KVkVSU0lPTjoyLjANCkJFR0lOOlZFVkVOVA0KVUlEOmJvb2stMjVAeHh4DQpPUkdBTklaRVI7Q049Q2hyaXN0b3BoZXIgQ2FybHNzb246bWFpbHRvOnh4eA0KQVRURU5ERUU7Uk9MRT1SRVEtUEFSVElDSVBBTlQ7Q049Q2hyaXN0b3BoZXIgQ2FybHNzb246bWFpbHRvOnh4eA0KQUNUSU9OO1JTVlA9VFJVRTtDTj1DaHJpc3RvcGhlciBDYXJsc3NvbjtYLU5VTS1HVUVTVFM9MDptYWlsdG86eHh4DQpEVFNUQVJUOjIwMTcwODA0VDEzNDUwMFoNCkRURU5EOjIwMTcwODA0VDE0MDAwMFoNCkRUU1RBTVA6MjAxNzA4MDRUMTEyNjI1Wg0KU1VNTUFSWTpUZXN0DQpERVNDUklQVElPTjp0ZXN0DQpMT0NBVElPTjpUZXN0cmVzdXJzDQpTRVFVRU5DRToxDQpTVEFUVVM6Q09ORklSTUVEDQpFTkQ6VkVWRU5UDQpFTkQ6VkNBTEVOREFS
--b1_d83d69dae575b544ae866adb06fa17e53e7014bfcc12978a468b83895932fa87--
Does anyone have known-working examples for all the places that we want this to work that they could share? I'm working pretty much blind here.
I happened to get sent an invitation from Apple's iCal service on iCloud. The email structure looks like this:
Content-Type: multipart/mixed;
boundary="----=_Part_889321_1826442293.1503391415807"
------=_Part_889321_1826442293.1503391415807
Content-Type: multipart/alternative;
boundary="----=_Part_889322_1826442187.1503391415807"
------=_Part_889322_1826442187.1503391415807
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: QUOTED-PRINTABLE
Content-Disposition: inline
text part
------=_Part_889322_1826442187.1503391415807
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: QUOTED-PRINTABLE
Content-Disposition: inline
HTML part
------=_Part_889322_1826442187.1503391415807--
------=_Part_889321_1826442293.1503391415807
Content-Type: text/calendar; method=REQUEST
Content-Transfer-Encoding: Base64
Content-Disposition: attachment; filename=iCal-20170822-014335.ics
ical part
------=_Part_889321_1826442293.1503391415807--
This message does nothing special in Mail on either macOS or iOS. There are buttons displayed, but they are just HTML from the HTML part, and the iCal part is shown as an attachment. Note that the text/calendar
part is not part of the multipart/alternative
structure - it's a simple attachment within the root multipart/mixed
element. That said, while it did nothing within Mail, the Calendar app on macOS displayed a notification several minutes later containing close and accept buttons, though I have no way of telling if this was triggered by the email or one of my calendar subscriptions. What I really need is details of the MIME structure & headers that causes Outlook to do its thing.
https://forums.phpfreaks.com/topic/157171-solved-phpmailer-custom-content/?p=829136
@gunkire The PHPMailer code is already doing the same as what's in that example.
I've finally solved this outside of PHPMailer, using PHP's own mail function. The issue seems to have been that the VCALENDAR object needed to have a timezone specified - this gave me the RSVP buttons.
$reservation = Reservation::with('user')->with('resource')->find($id); $boundary = "--" . md5(time()); $origin_format = 'Y-m-d H:i:s'; $format = 'Ymd\THis';
$headers = "From: My sender [email protected]\n"; $headers .= "Reply-To: My sender [email protected]\n"; $headers .= "Content-Type: text/calendar; method=REQUEST;boundary="" . $boundary . "";charset="utf-8"\n"; $headers .= "Content-Transfer-Encoding: 7bit\n";
$ical ="X-Mailer: Microsoft Office Outlook 12.0 BEGIN:VCALENDAR PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN VERSION:2.0 METHOD:REQUEST X-MS-OLK-FORCEINSPECTOROPEN:TRUE BEGIN:VTIMEZONE TZID:UTC BEGIN:STANDARD DTSTART:20171010T000000 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 TZOFFSETFROM:+0000 TZOFFSETTO:+0000 END:STANDARD BEGIN:DAYLIGHT DTSTART:20170310T000000 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3 TZOFFSETFROM:+0000 TZOFFSETTO:+0000 END:DAYLIGHT END:VTIMEZONE BEGIN:VEVENT ATTENDEE;CN="'" . $reservation->user->name . "'";RSVP=TRUE:mailto:" . $reservation->user->email . " CLASS:PUBLIC CREATED:" . Carbon::now()->format('Ymd\THis') . " DTEND;TZID="UTC":" . Carbon::createFromFormat($origin_format, $reservation->ends_at)->format($format) . " DTSTAMP:" . Carbon::now()->format('Ymd\THis') . " DTSTART;TZID="UTC":" . Carbon::createFromFormat($origin_format, $reservation->starts_at)->format($format) . " LAST-MODIFIED:20171113T133000 LOCATION:" . $reservation->resource->label . " ORGANIZER;CN=Meetio Book:mailto:[email protected] PRIORITY:5 SEQUENCE:1 SUMMARY:Updated: " . $reservation->title . " TRANSP:OPAQUE UID:" . str_random(40) . " END:VEVENT END:VCALENDAR"; $subject = $reservation->title;
$mail_sent = mail($reservation->user->email, $subject, $ical, $headers);
Hope this helps you solve the issue in PHPMailer.
... is there any solution with PhpMailer 5.2? Maybe in the new version of PhpMailer?
You can try to set those headers for PHPMAILER : $mail->CharSet = 'utf-8'; $mail->ContentType = 'text/calendar;method=REQUEST'; $mail->Encoding = '7bit';