Php 如何让.ics为Outlook工作(Laravel mailer)?

Php 如何让.ics为Outlook工作(Laravel mailer)?,php,laravel,email,outlook,icalendar,Php,Laravel,Email,Outlook,Icalendar,我正在尝试让Outlook将我的电子邮件的.ics文件识别为适当的邀请。ics日历邀请函在Gmail中运行得很好,只是在Outlook中不行。通过阅读其他Stackoverflow帖子,我的猜测是我没有正确设置“MIME”等,但我不知道怎么做(我对电子邮件有点生疏) 这是我的基本代码的一个片段 Mail::send($data['view'], $data['data'], function($message) use ($data) { $message->from($from

我正在尝试让Outlook将我的电子邮件的.ics文件识别为适当的邀请。ics日历邀请函在Gmail中运行得很好,只是在Outlook中不行。通过阅读其他Stackoverflow帖子,我的猜测是我没有正确设置“MIME”等,但我不知道怎么做(我对电子邮件有点生疏)

这是我的基本代码的一个片段

Mail::send($data['view'], $data['data'], function($message) use ($data)  {
    $message->from($from_email,$f_n)->to($to_email)->subject($data['subject']);
    $message->attachData($data['ical'], 'invite.ics');
});
我试过这样的代码:

$message->setContentType("text/calendar;method=REQUEST;name=\"invite.ics\"");
$disp->addParameterizedHeader(
    'Content-Disposition', 'x'
);
$disp = $message->getHeaders()->get('Content-Disposition');
$disp->setValue('attachment');
$disp->setParameter('filename', 'invite.ics');

但到目前为止运气不好。 我用的是拉威尔5.5

为了支持问题与.ics文件本身无关的观点,我尝试使用标准的Google Calendar生成的invitation.ics,当通过Google Calendar中的自动电子邮件发送时,它确实与Outlook一起工作,但当我通过我的
Mail::send
发送时,它就不起作用了


提前感谢您的建议

我最终为一个Laravel 4应用程序做的是扩展邮件程序,然后将
MailServiceProvider
替换为我自己的,添加一个额外的方法
invite

public function invite($view, array $data, $callback)
{
    // First we need to parse the view, which could either be a string or an array
    // containing both an HTML and plain text versions of the view which should
    // be used when sending an e-mail. We will extract both of them out here.
    list($view, $plain) = $this->parseView($view);

    $data['message'] = $message = $this->createMessage();

    $ts = \Carbon\Carbon::now();

    $filename = "invite.ics";
    $meeting_duration = (60 * 60); // 5 minutes
    $meetingstamp = $ts->getTimeStamp();
    $dtstart = gmdate('Ymd\THis\Z', $meetingstamp);
    $dtend =  gmdate('Ymd\THis\Z', $meetingstamp + $meeting_duration);
    $todaystamp = gmdate('Ymd\THis\Z');
    $uid = date('Ymd').'T'.date('His').'-'.rand();
    $description = $data['event']['description'];
    $location = $data['event']['location'];

    $organizer = "Organizer name:" . $data['event']['organizername'];
    $organizerEmail = 'noreply@email.com';

    //Including additional headers
    $typemime = $message->getHeaders()->get("MIME-version");
    $typemime->setValue("1.0");
    $type = $message->getHeaders()->get("Content-Type");
    $type->setValue("text/calendar");
    $type->setParameters(array(
        "name" => "calendar.ics",
        "method" => "REQUEST",
        "charset" => "iso-8859-1"
    ));

    $typetrans = $message->getHeaders()->get("Content-Transfer-Encoding");
    $typetrans->setValue("7bit");
    $message->getHeaders()->addTextHeader("X-Mailer", "Microsoft Office Outlook 12.0");

    //vCalendar parameters
    $vcal = "BEGIN:VCALENDAR\r\n";
    $vcal .= "VERSION:2.0\r\n";
    $vcal .= "PRODID:-//yourdomain.com//OrgCalendarWebTool//EN\r\n";
    $vcal .= "METHOD:REQUEST\r\n";
    $vcal .= "BEGIN:VEVENT\r\n";
    $vcal .= "ORGANIZER;CN=\"$organizer"."\":mailto:$organizerEmail\r\n";
    $vcal .= "UID:".$uid;
    $vcal .= "DTSTAMP:".date('Ymd').'T'.date('His')."\r\n";
    $vcal .= "DTSTART:$dtstart\r\n";
    $vcal .= "DTEND:$dtend\r\n"; 
    $vcal .= "LOCATION:$location\r\n";
    $vcal .= "SUMMARY:$description\r\n";
    $vcal .= "DESCRIPTION:$description \r\n";
    $vcal .= "BEGIN:VALARM\r\n";
    $vcal .= "TRIGGER:-PT15M\r\n";
    $vcal .= "ACTION:DISPLAY\r\n";
    $vcal .= "DESCRIPTION:Reminder\r\n";
    $vcal .= "END:VALARM\r\n";
    $vcal .= "END:VEVENT\r\n";
    $vcal .= "END:VCALENDAR\r\n";

    //Adding the parameters (This part Im not sure how to do it)
    $message->addPart($vcal, 'text/calendar; method=REQUEST', 'iso-8859-1');

    $this->callMessageBuilder($callback, $message);

    // Once we have retrieved the view content for the e-mail we will set the body
    // of this message using the HTML type, which will provide a simple wrapper
    // to creating view based emails that are able to receive arrays of data.
    $this->addContent($message, $view, $plain, $data);

    $message = $message->getSwiftMessage();

    return $this->sendSwiftMessage($message);
}
通过这种方式,使用变得更加简单:

// send a calendar invite
Mail::invite(...
// send a regular email
Mail::send(...
Laravel 5添加了一些新功能,如邮件功能,因此我建议查看源代码以确定您可能需要什么

邮件来源:


我不记得在哪里找到
vCalendar
参数的语法。如果我找到了,我会把它添加到这里。

我刚刚发现,可以将mime参数添加到attachData函数中(根据)-这对Outlook和Gmail都有效。耶:)


嗨,你有包括ical在内的完整示例吗?谢谢!这最终启用了我正在搜索的outlook中的接受和拒绝功能!非常感谢!
// send a calendar invite
Mail::invite(...
// send a regular email
Mail::send(...
$message->attachData($data['ical'], 'invite.ics', [
                    'mime' => 'text/calendar;charset=UTF-8;method=REQUEST',
                ]);