2017-07-12 101 views
7

我使用Laravel的郵件API發送日曆邀請。在Outlook中收到日曆邀請作爲ICS文件 - Laravel

該日曆在gmail上看起來不錯,但在outlook上顯示附件而不是正確的日曆邀請。

Gmail的輸出:

enter image description here

,而在前景似乎是附件:

enter image description here

我創建名稱爲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")); 


}); 
+0

你嘗試過'$ message-> attach('invite.ics',array('mime'=>'text/calendar; charset =「utf-8」; method = REQUEST'));'? – alepeino

+0

我想我做了,我會再試一次@alepeino –

+0

@alepeino它沒有工作 –

回答

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正文中的電子郵件。

相關問題