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

Dan*_*elo 7 php outlook calendar laravel-5

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

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

Gmail的输出:

在此输入图像描述

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

在此输入图像描述

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

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


});
Run Code Online (Sandbox Code Playgroud)

Dan*_*elo 5

这就是我的工作方式

$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");
Run Code Online (Sandbox Code Playgroud)

在正文中添加了日历并将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);
            }
        });
Run Code Online (Sandbox Code Playgroud)