Calendar invite is received as ICS file in outlook - 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
基础教程推荐
- 使用 PDO 转义列名 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01