沃梦达 / 编程问答 / php问题 / 正文

日历邀请在 Outlook 中作为 ICS 文件接收 - Laravel

Calendar invite is received as ICS file in outlook - Laravel(日历邀请在 Outlook 中作为 ICS 文件接收 - Laravel)

本文介绍了日历邀请在 Outlook 中作为 ICS 文件接收 - Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Laravel 的邮件 API 发送日历邀请.

I am sending calendar invite using Laravel's mail api.

日历在 Gmail 上看起来不错,但在 Outlook 上显示附件而不是正确的日历邀请.

The calendar looks good on gmail but shows an attachment on outlook instead of proper calendar invitation.

Gmail 的输出:

从外观上看,它似乎是一个附件:

我正在创建一个名为invite.ics 的文件,并将内容放入invite.ics 文件中,我在发送电子邮件时附加了该文件.

I am creating a file with name invite.ics and I put the content inside the invite.ics file, I attach the file while sending the email.

$to = $row->to;
$subject = $row->subject;
$attachments = $row->attachment;
$cc = $row->cc;
$body = $row->body;
$calendar_invitation = $row->calendar_invitation;

Mail::send(
'emailTemplates.dummy', 
['emailBody'=>$row->body],  
function(Message $message) use ($to,$subject,$attachments,$cc, $body, $calendar_invitation, $companyEmail)
{
    $message->from($companyEmail, '');
    $message->replyTo($companyEmail, 'Email Agent Evmeetings');
    $message->to($to, '')->subject($subject);
    $file = fopen("invite.ics","w");
    echo fwrite($file,$calendar_invitation);
    fclose($file);
    $message->attach('invite.ics', array('mime' => "text/calendar"));


});

推荐答案

我就是这样做的

$message->from($companyEmail, '');
$message->replyTo($companyEmail, 'Email Agent Evmeetings');
$message->to($to, '')->subject($subject);
$message->setBody($calendar_invitation, 'text/calendar; charset="utf-8"; method=REQUEST');
$message->addPart($body, "text/html");

在body中添加了日历并将mime类型更改为'text/calendar;字符集=utf-8";method=REQUEST'

Added the calendar in body and changed the mime type to 'text/calendar; charset="utf-8"; method=REQUEST'

并使用 addPart($body, "text/html"); 方法在电子邮件中添加 html 正文.

and used addPart($body, "text/html"); method to add html body in the email.

完整代码:

        Mail::send('emailTemplates.dummy', ['emailBody'=>$row->body],  function(Message $message) use ($to,$subject,$attachments,$cc, $body, $calendar_invitation, $companyEmail,$replyTo)
        {
            $message->from($companyEmail, trim(env("email_agent_name")));
            $message->replyTo($replyTo, trim(env("email_agent_email")));
            $message->to($to, '')->subject($subject);
            $message->setBody($calendar_invitation, 'text/calendar; charset="utf-8"; method=REQUEST');
            $message->addPart($body, "text/html");

            $attachments = unserialize($attachments);
            foreach($attachments as $attachment){
                if(file_exists(public_path()."/".$attachment['location'])){

                    $message->attach(public_path()."/".$attachment['location'], array('as'=>$attachment['name'].".".pathinfo(parse_url($attachment['location'])['path'], PATHINFO_EXTENSION),
                        'mime' => mime_content_type ( public_path()."/".$attachment['location']) ));
                }
            }
            $cc = unserialize($cc);
            foreach($cc as $anotherEmail){
                $message->cc($anotherEmail);
            }
        });

这篇关于日历邀请在 Outlook 中作为 ICS 文件接收 - Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:日历邀请在 Outlook 中作为 ICS 文件接收 - Laravel

基础教程推荐