Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get .ics to work for Outlook (Laravel mailer)?

I'm trying to get Outlook to recognise my email's .ics file as a proper invite. The .ics calendar invitation does work perfectly in Gmail, just not Outlook. From reading other Stackoverflow posts, my guess is that I haven't set the "MIME" etc correctly, but I can't figure out how to do it (I'm a bit of a newbie to email).

Here's a snippet of my base code.

Mail::send($data['view'], $data['data'], function($message) use ($data)  {
    $message->from($from_email,$f_n)->to($to_email)->subject($data['subject']);
    $message->attachData($data['ical'], 'invite.ics');
});

I've tried code like:

$message->setContentType("text/calendar;method=REQUEST;name=\"invite.ics\"");
$disp->addParameterizedHeader(
    'Content-Disposition', 'x'
);
$disp = $message->getHeaders()->get('Content-Disposition');
$disp->setValue('attachment');
$disp->setParameter('filename', 'invite.ics');

and

$message->setBody($data['ical'], 'text/calendar; charset="utf-8"; method=REQUEST');

But no luck so far. I'm using Laravel 5.5.

To support the idea that the problem isn't to do with the .ics file itself, I've tried using a standard Google Calendar generated invitation .ics, which does work with Outlook when sent via automated email from Google Calendar, but not when I send it via my Mail::send.

Thanks in advance for any advice!

like image 668
user6122500 Avatar asked Nov 17 '25 16:11

user6122500


1 Answers

I've just found out that you can add mime parameters to the attachData function (as per https://laravel.com/docs/5.7/mail#attachments) - this works for both Outlook and Gmail. Yay :)

$message->attachData($data['ical'], 'invite.ics', [
                    'mime' => 'text/calendar;charset=UTF-8;method=REQUEST',
                ]);
like image 135
user6122500 Avatar answered Nov 19 '25 05:11

user6122500



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!