在Laravel 4.1中将.ics事件作为电子邮件附件发送

时间:2014-03-12 07:46:50

标签: php email laravel calendar attachment

我正在尝试使用Laravel的MAIL课程将.ics文件作为电子邮件附件发送。收到电子邮件后,Gmail不会要求我向日历添加活动。但是,我可以通过上传收到的文件轻松地将事件添加到日历中。 (格式有效。)并且还有一个小日历图标,但根本没有花哨的格式或任何格式。 这是我正在使用的代码:

$filename = "invite.ics";

$data[0]  = "BEGIN:VCALENDAR";
$data[1] = "PRODID:-//Google Inc//Google Calendar 70.9054//EN";
$data[2] = "VERSION:2.0";
$data[3] = "CALSCALE:GREGORIAN";
$data[4] = "METHOD:REQUEST";
$data[8] = "BEGIN:VEVENT";
$data[9] = "DTSTART:20140312T080000Z";
$data[10] = "DTEND:20140312T103000Z";
$data[11] = "DTSTAMP:20140312T072230Z";
$data[12] = "UID:aj5nufn03q772ukb54u1pp6c88@example.com";
$data[13] = "CREATED:20140312T072126Z";
$data[14] = "DESCRIPTION:Hair cut\, 2\,5h\, 300Eur";
$data[15] = "LAST-MODIFIED:20140312T072206Z";
$data[16] = "LOCATION:";
$data[17] = "SEQUENCE:0";
$data[18] = "STATUS:CONFIRMED";
$data[19] = "SUMMARY:Matu griešana";
$data[20] = "TRANSP:OPAQUE";
$data[21] = "END:VEVENT";
$data[22] = "END:VCALENDAR";


$data = implode("\r\n", $data);
header("text/calendar");
file_put_contents($filename, "\xEF\xBB\xBF".  $data);

Mail::send('emails.temp', array(), function($message) use($filename)
{
    $message->from('jon@example', 'Jon Doe');
    $message->to('osvalds.neiders@gmail.com')->subject('Registration information');

    $message->attach($filename, array('mime' => "text/calendar"));
});

1 个答案:

答案 0 :(得分:-1)

在目标上创建一个文件并附上它

name ="invite.ics"
matter= 
"BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
ORGANIZER:MAILTO:aaaa@aaaa.com
DTSTART:20150315T170000Z
DTEND:20150315T180000Z
LOCATION:La Taska
TRANSP:OPAQUE
SEQUENCE:0
UID:d41d8cd98f00b204e9800998ecf8427e
DTSTAMP:20150313T150000Z
DESCRIPTION:The Programn Description
SUMMARY:The Programn Description
PRIORITY:5
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR"