使用PHPMailer将Ical约会发送到Office 365

时间:2018-12-03 13:45:47

标签: php outlook office365 phpmailer icalendar

我正在使用最新版本的PHPMailer 5.5版

下面是我编写的代码,我正在尝试向公司内的Office 365应用程序发送Ical约会,但是它没有显示RSVP按钮,它只是将日历约会添加为附件。

我尝试使用在网上找到的各种教程来进行设置,但是没有运气,我认为这取决于您所使用的Outlook版本等。

当电子邮件通过后,我可以打开附件并将其添加到日历中,但是它应该自动显示按钮,以允许您接受,暂定或拒绝约会。

我实际上是使用我们自己的Outlook应用程序通过导出.ics文件并按如下所示进行设置来生成以下$ ical代码的。

我相信这可能与标头有关,但也许更了解Outlook的人可以提供帮助?

谢谢。

$mail = new PHPMailer();
$mail = $this->setSMTPDetails($mail);

$mail->IsHTML(false);
$mail->setFrom('webdevelopment@chandcogroup.com', 'CH&CO Team');
$mail->addReplyTo('webdevelopment@chandcogroup.com', 'CH&CO Team');
$mail->addAddress($email,'Danny');
$mail->ContentType = 'text/calendar';

$mail->Subject = "WBBW day booking";
$mail->addCustomHeader('MIME-version',"1.0");

$ical ="BEGIN:VCALENDAR\r\n";
$ical .="PRODID:-//Microsoft Corporation//Outlook 16.0 MIMEDIR//EN\r\n";
$ical .="VERSION:2.0\r\n";
$ical .="METHOD:REQUEST\r\n";
$ical .="X-MS-OLK-FORCEINSPECTOROPEN:TRUE\r\n";
$ical .="BEGIN:VTIMEZONE\r\n";
$ical .="TZID:GMT Standard Time\r\n";
$ical .="BEGIN:STANDARD\r\n";
$ical .="DTSTART:16011028T020000\r\n";
$ical .="RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10\r\n";
$ical .="TZOFFSETFROM:+0100\r\n";
$ical .="TZOFFSETTO:-0000\r\n";
$ical .="END:STANDARD\r\n";
$ical .="BEGIN:DAYLIGHT\r\n";
$ical .="DTSTART:16010325T010000\r\n";
$ical .="RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3\r\n";
$ical .="TZOFFSETFROM:-0000\r\n";
$ical .="TZOFFSETTO:+0100\r\n";
$ical .="END:DAYLIGHT\r\n";
$ical .="END:VTIMEZONE\r\n";
$ical .="BEGIN:VEVENT\r\n";
$ical .="ATTENDEE;CN='Danny Hardy';RSVP=TRUE:mailto:webdevelopment@chandcogroup.com\r\n";
$ical .="CLASS:PUBLIC\r\n";
$ical .="CREATED:20181203T112515Z\r\n";
$ical .="DESCRIPTION: WBBW Day Booking\r\n";
$ical .="DTEND;TZID='GMT Standard Time':20181210T130000\r\n";
$ical .="DTSTAMP:20181203T111806Z\r\n";
$ical .="DTSTART;TZID='GMT Standard Time':20181210T120000\r\n";
$ical .="LAST-MODIFIED:20181203T112515Z\r\n";
$ical .="LOCATION:TVP\r\n";
$ical .="ORGANIZER;CN='James Gambrill':mailto:James.Gambrill@chandcogroup.com\r\n";
$ical .="PRIORITY:5\r\n";
$ical .="SEQUENCE:0\r\n";
$ical .="SUMMARY:Catch up Danny / James\r\n";
$ical .="TRANSP:OPAQUE\r\n";
$ical .="UID:040000008200E00074C5B7101A82E0080000000090974ADDF98AD401000000000000000
010000000016A2E1A28D2CB4F94035AA4D93C7DE9\r\n";
$ical .="X-ALT-DESC;FMTTYPE=text/html:<html xmlns:v='urn:schemas-microsoft-com:vml'
xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-mic
rosoft-com:office:word' xmlns:m='http://schemas.microsoft.com/office/2004/
12/omml' xmlns='http://www.w3.org/TR/REC-html40'><head>\n<meta name='Gener
ator' content='Microsoft Word 15 (filtered medium)'><style><!--\n/* Font D
efinitions */\n@font-face\n {font-family:'Cambria Math'\;\n panose-1:2 4 5
 3 5 4 6 3 2 4\;}\n@font-face\n {font-family:Calibri\;\n    panose-1:2 15 5 2
 2 2 4 3 2 4\;}\n/* Style Definitions */\np.MsoNormal\, li.MsoNormal\, div
.MsoNormal\n    {margin:0cm\;\n margin-bottom:.0001pt\;\n   font-size:11.0pt\;\
n   font-family:'Calibri'\,sans-serif\;\n   mso-fareast-language:EN-US\;}\na:l
ink\, span.MsoHyperlink\n   {mso-style-priority:99\;\n  color:#0563C1\;\n   tex
t-decoration:underline\;}\na:visited\, span.MsoHyperlinkFollowed\n  {mso-st
yle-priority:99\;\n color:#954F72\;\n   text-decoration:underline\;}\np.mson
ormal0\, li.msonormal0\, div.msonormal0\n   {mso-style-name:msonormal\;\n   ms
o-margin-top-alt:auto\;\n   margin-right:0cm\;\n    mso-margin-bottom-alt:auto\
;\n margin-left:0cm\;\n font-size:11.0pt\;\n    font-family:'Calibri'\,sans-s
erif\;}\nspan.EmailStyle18\n    {mso-style-type:personal-compose\;\n    font-fam
ily:'Calibri'\,sans-serif\;\n   color:windowtext\;}\n.MsoChpDefault\n   {mso-s
tyle-type:export-only\;\n   font-size:10.0pt\;}\n@page WordSection1\n   {size:
612.0pt 792.0pt\;\n margin:72.0pt 72.0pt 72.0pt 72.0pt\;}\ndiv.WordSection
1\n {page:WordSection1\;}\n--></style><!--[if gte mso 9]><xml>\n<o:shapede
faults v:ext='edit' spidmax='1026' />\n</xml><![endif]--><!--[if gte mso 9
]><xml>\n<o:shapelayout v:ext='edit'>\n<o:idmap v:ext='edit' data='1' />\n
</o:shapelayout></xml><![endif]--></head><body lang='EN-GB' link='#0563C1'
 vlink='#954F72'><div class='WordSection1'><p class='MsoNormal'><o:p>&nbsp
\;</o:p></p></div></body></html>\r\n";
$ical .="X-MICROSOFT-CDO-BUSYSTATUS:BUSY\r\n";
$ical .="X-MICROSOFT-CDO-IMPORTANCE:1\r\n";
$ical .="X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\n";
$ical .="X-MICROSOFT-DISALLOW-COUNTER:FALSE\r\n";
$ical .="BEGIN:VALARM\r\n";
$ical .="TRIGGER:-PT15M\r\n";
$ical .="ACTION:DISPLAY\r\n";
$ical .="DESCRIPTION:Reminder\r\n";
$ical .="END:VALARM\r\n";
$ical .="END:VEVENT\r\n";
$ical .="END:VCALENDAR\r\n";

$mail->Ical = "$ical";
$mail->Body = "This is the body";
$mail->AltBody = "This is the body";

try {
 $mail->Send();
}
catch (Exception $e) {
 mail("webdevelopment@chandcogroup.com", "Error with sending customer WBBW email on website", "$mail->ErrorInfo");
}
}

0 个答案:

没有答案