2017-07-12 27 views
7

Tôi đang gửi thư mời lịch bằng cách sử dụng api thư của Laravel.Lời mời lịch được nhận dưới dạng tệp ICS trong triển vọng - Laravel

Lịch có vẻ tốt trên gmail nhưng hiển thị tệp đính kèm trên triển vọng thay vì lời mời lịch thích hợp.

đầu ra của Gmail:

enter image description here

trong khi triển vọng nó có vẻ là tập tin đính kèm:

enter image description here

tôi đang tạo ra một tập tin với invite.ics tên và tôi đặt nội dung bên trong tệp invite.ics, tôi đính kèm tệp trong khi gửi 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")); 


}); 
+0

Bạn đã thử '$ message-> attach ('invite.ics', mảng ('mime' => 'văn bản/lịch; charset =" utf-8 "; method = REQUEST'));'? – alepeino

+0

Tôi đoán là tôi đã làm, tôi sẽ thử lại @alepeino –

+0

@alepeino nó không hoạt động –

Trả lời

4

Đó là cách tôi đã làm cho nó làm việc

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

Added lịch trong cơ thể và thay đổi loại mime để 'text/calendar; charset="utf-8"; method=REQUEST'

và sử dụng addPart($body, "text/html"); phương pháp để thêm nội dung html trong email.

Các vấn đề liên quan