在Outlook中将日历邀请作为ICS文件接收-Laravel [英] Calendar invite is received as ICS file in outlook - 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的输出:
在展望期间,它似乎是附件:
我正在创建一个名称为vital.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");
将日历添加到正文中,并将mime类型更改为'text/calendar; charset="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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!