本文介绍了使用Swift Mailer和Send Grid发送ics日历邀请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用sendgrid和swiftmailer向Gmail发送日历邀请.这是我的全部代码:

I'm trying to send a calendar invite to Gmail using sendgrid and swiftmailer. This is my entire code:

<html>
<head>
    <title>PHP Test</title>
</head>
<body>

<?php

require_once('path/to/lib/swift_required.php');
require('path/to/smtpapi-php.php');

$transport = \Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
$transport->setUsername('uname');
$transport->setPassword('pass');

$mailer = \Swift_Mailer::newInstance($transport);

$ical="BEGIN:VCALENDAR\r\n
PRODID:-//Microsoft Corporation//Outlook 14.0 MIMEDIR//EN\r\n
VERSION:2.0\r\n
METHOD:REQUEST\r\n
Content-Type: text/calendar; charset="utf-8"; name="invite.ics"; method=REQUEST'."\r\n";
Content-Disposition: inline; filename="invite.ics"'."\r\n;
BEGIN:VEVENT\r\n
ATTENDEE;[email protected];RSVP=
    TRUE:mailto:[email protected]\r\n
CLASS:PUBLIC\r\n
CREATED:20110803T133418Z\r\n
DTEND:20150429T035959Z\r\n
DTSTAMP:20110803T095605Z\r\n
DTSTART:$20150429T170000Z\r\n
LAST-MODIFIED:20110803T133418Z\r\n
ORGANIZER;CN=\"bbb\":mailto:
 [email protected]\r\n
PRIORITY:5\r\n
SEQUENCE:0\r\n
SUMMARY;LANGUAGE=ro:New Event\r\n
TRANSP:OPAQUE\r\n
UID:".MD5(TIME())."-85d2-69b00dea0ad4\r\n
X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE\r\n
X-MICROSOFT-CDO-IMPORTANCE:1\r\n
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\n
X-MICROSOFT-DISALLOW-COUNTER:FALSE\r\n
X-MS-OLK-AUTOSTARTCHECK:FALSE\r\n
X-MS-OLK-CONFTYPE:0\r\n
BEGIN:VALARM\r\n
TRIGGER:-PT15M\r\n
ACTION:DISPLAY\r\n
DESCRIPTION:Reminder\r\n
END:VALARM\r\n
END:VEVENT\r\n
END:VCALENDAR\r\n";

$attachment = Swift_Attachment::newInstance()
    ->setFilename("invite.ics")
    ->setContentType('multipart/alternative;charset=UTF-8;name="invite.ics";method=REQUEST')
    ->setBody($ical)
    ->setDisposition('inline;filename=invite.ics');


$message = new \Swift_Message();
$message->setTo(array('[email protected]'));
$message->setFrom('[email protected]');
$message->setSubject('Hello');
$message->attach($attachment);

try {
    $response = $mailer->send($message);
    print_r($response);
} catch(\Swift_TransportException $e) {
    print_r('Bad username / password');
}

?>

</body>
</html>

正在发生的情况是,它正在发送带有ics附件的电子邮件,但gmail和Outlook无法识别其日历邀请.你能帮我吗?

What is happening is that it is sending the email with the ics attachment but gmail and outlook are not recognizing that its a calendar invite. Can you please help me?

我已将此链接用作参考: Outlook无法识别的ics文件

I've used this link as reference:ics file not recognized by outlook

推荐答案

我立即看到了一些问题:

Some problems I see immediately:

  1. 您未指定text/calendar内容类型.
  2. 您在content-type标头和其他位置使用了错误的引号. (而不是").
  3. 您要嵌入三重换行符(\n\r\n),因为您同时具有 real 换行符和\r\n.
  1. You are not specifying a text/calendar content type.
  2. You are using the wrong quotes in the content-type header and various other places. (" instead of ").
  3. You are embedding triple-newlines (\n\r\n) because you have both a real newline and a \r\n.

这可能无法解决,但这是一个起点.我建议您仔细查看您发送的电子邮件的来源,并将其与可以正常工作的iMip邀请进行比较.我认为这不是唯一的问题.

This might not fix it, but it's a starting point. I would recommend taking a good look at the source of the email you are sending, and compare it to a correctly working iMip invite. I'd assume it's not the only problem.

这篇关于使用Swift Mailer和Send Grid发送ics日历邀请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 19:52