日历邀请作为Outlook中的ICS文件收到 - Laravel

时间:2017-07-12 10:30:08

标签: php laravel-5 outlook calendar

我正在使用Laravel的邮件api发送日历邀请。

日历在gmail上看起来不错,但在outlook上显示附件而不是正确的日历邀请。

Gmail的输出:

enter image description here

在展望期间它似乎是一个附件:

enter image description here

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

URL

1 个答案:

答案 0 :(得分:4)

我的工作方式

$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");

在正文中添加了日历,并将mime类型更改为'text/calendar; charset="utf-8"; method=REQUEST'

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

完整代码:

        \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);
            }
        });