在 Outlook 中以 ICS 文件形式接收日历邀请 - Laravel

2024-01-15

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

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

Gmail 的输出:

在 Outlook 上,它似乎是一个附件:

我正在创建一个名为 inform.ics 的文件,并将内容放入 inform.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"));


});

我就是这样让它发挥作用的

$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);
            }
        });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Outlook 中以 ICS 文件形式接收日历邀请 - Laravel 的相关文章

随机推荐