我正在通过php发送会议邀请。我的代码确实发送了会议邀请(最终用户可以看到会议邀请)但是我无法设置html说明。
我怀疑问题可能是因为我使用字符串变量将参数传递给X-ALT-DESC
。在邀请中,可以看到纯文本,我通过DESCRIPTION
标记设置,但HTML文本不是。如果Outlook 2007收到邀请,他应该看到HTML文本吗?
以下是代码:
$aHeaders = array();
$aHeaders[] = 'MIME-Version: 1.0';
$aHeaders[] = 'Content-Type: text/calendar; method=REQUEST';
$aHeaders[] = 'Content-Class: urn:content-classes:calendarmessage';
$aHeaders[] = 'From: abc@xyz.com';
$aHeaders[] = 'Reply-To: abc@xyz.com';
$sHeaders = implode("\r\n", $aHeaders);
$sBody .= "BEGIN:VCALENDAR\r\n";
$sBody .= "PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN\r\n";
$sBody .= "VERSION:2.0\r\n";
$sBody .= "METHOD:REQUEST\r\n";
$sBody .= "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\r\n";
$sBody .= "BEGIN:VEVENT\r\n";
$sBody .= "ATTENDEE:mailto:" . $sTo . "\r\n";
$sBody .= "ORGANIZER;CN=ABC:mailto:ABC@XYZ.com\r\n";
$sBody .= "DTSTAMP:'.date('Ymd').'T'.date('His').'Z''\r\n";
$sBody .= "DTSTART:" . $sConfstart . "\r\n";
$sBody .= "DTEND:" . $sConfend . "\r\n";
$sBody .= "LOCATION:Conference Call\r\n";
$sBody .= "TRANSP:OPAQUE\r\n";
$sBody .= "SEQUENCE:0\r\n";
$sBody .= "UID:'. md5(uniqid(mt_rand(), true)) .'\r\n";
$sBody .= "SUMMARY:" . $sSubject . "\r\n";
$sBody .= "PRIORITY:5\r\n";
$sBody .= "CLASS:PUBLIC\r\n";
$sBody .= "DESCRIPTION:this is plain desc"\r\n";
$sBody .= "X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\"><HTML><BODY>html goes here</BODY></HTML>\r\n";
$sBody .= "END:VEVENT\r\n";
$sBody .= "END:VCALENDAR\r\n";
---- EDIT 这是生成的iCalendar字符串
BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN
VERSION:2.0
METHOD:REQUEST
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VEVENT
ATTENDEE;CN="Test_DM@xyz.com, test1@xyz.com";RSVP=TRUE:mail
to:Test_DM@xyz.com\, test1@xyz.com
CLASS:PUBLIC
CREATED:20140222T144724Z
DESCRIPTION:this is plain desc
DTEND:20140223T140000Z
DTSTAMP:20140222T144640Z
DTSTART:20140223T130000Z
LAST-MODIFIED:20140222T144724Z
LOCATION:Conference Call
ORGANIZER;CN="test_org":mailto:test_org@xyz.com
PRIORITY:5
SEQUENCE:0
SUMMARY;LANGUAGE=en-us:
TRANSP:OPAQUE
UID:20140222T144640Z
X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//E
N">\n<HTML>\n<HEAD>\n<META NAME="Generator" CONTENT="MS Exchange Server ve
rsion 08.00.0681.000">\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n<!-- Converted f
rom text/plain format -->\n\n<P><FONT SIZE=2><\;!DOCTYPE HTML PUBLIC &qu
ot\;-//W3C//DTD HTML 3.2//EN"\;>\;<\;HTML>\;<\;BODY>\;html g
oes here<\;/BODY>\;<\;/HTML>\;</FONT>\n</P>\n\n</BODY>\n</HTML>
X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR
答案 0 :(得分:0)
我已经很晚了,但对于那些在搜索结果中发现这一点的人来说......这不是&#34; THE&#34;回答,但这是一个适用于Outlook的答案。
我无法使用X-ALT-DESC等工作HTML,我仍然希望看到有人回答这个问题。但是,您可以通过创建multipart/alternative
电子邮件将HTML作为Outlook中事件的一部分。但是,虽然这适用于Outlook,但其他服务(例如Gmail)只会在活动中显示摘要/说明。
警告:这对防止标头注入没有任何作用,请负责任地使用 ; - )
<?php
date_default_timezone_set('America/New_York');
//CONFIGURE HERE
$fromName = "John Doe";
$fromEmail = "john.doe@example.com";
$toName = "Your Name";
$toEmail = 'yourname@example.com';
$start = new DateTime('2017-08-15 15:00');
$end = new DateTime('2017-08-15 16:00');
$summary = "Hello World Event";
//END CONFIGURATION
$uid = "0123456789";
$headers = array();
$boundary = "_CAL_" . uniqid("B",true) . "_B_";
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-Type: multipart/alternative; boundary=\"".$boundary."\"";
$headers[] = "To: \"{$toName}\" <{$toEmail}>";
$headers[] = "From: \"{$fromName}\" <{$fromEmail}>";
$calendarLines = array(
"BEGIN:VCALENDAR",
"METHOD:REQUEST",
"PRODID:-//PHP//MeetingRequest//EN",
"VERSION:2.0",
"BEGIN:VEVENT",
"ORGANIZER;CN={$fromName}:MAILTO:{$fromEmail}",
"ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN={$toName}:MAILTO:{$toEmail}",
"DESCRIPTION:{$summary}",
"SUMMARY:{$summary}",
"DTSTART:".$start->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z'),
"DTEND:".$end->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z'),
"UID:{$uid}",
"CLASS:PUBLIC",
"PRIORITY:5",
"DTSTAMP:".gmdate('Ymd\THis\Z'),
"TRANSP:OPAQUE",
"STATUS:CONFIRMED",
"SEQUENCE:0",
"LOCATION:123 Any Street",
"BEGIN:VALARM",
"ACTION:DISPLAY",
"DESCRIPTION:REMINDER",
"TRIGGER;RELATED=START:-PT15M",
"END:VALARM",
"END:VEVENT",
"END:VCALENDAR"
);
$calendarBase64 = base64_encode(implode("\r\n",$calendarLines));
//ensure we don't have lines longer than 70 characters for older computers:
$calendarResult = wordwrap($calendarBase64,68,"\n",true);
$emailLines = array(
"--{$boundary}",
"Content-Type: text/html; charset=\"iso - 8859 - 1\"",
"Content-Transfer-Encoding: quoted-printable",
"",
"<html><body>",
"<h1>Hello World</h1>",
"<p>This is a calendar event test</p>",
"</body></html>",
"",
"--{$boundary}",
"Content-Type: text/calendar; charset=\"utf - 8\"; method=REQUEST",
"Content-Transfer-Encoding: base64",
"",
$calendarResult,
"",
"--{$boundary}--"
);
$emailContent = implode("\n",$emailLines);
$headersResult = implode("\n",$headers);
mail($toEmail, $summary, $emailContent, $headersResult );
echo("<pre>".htmlentities($headersResult)."\n\n".htmlentities($emailContent)."</pre>");
echo("<br /><br />");
echo("<pre>".base64_decode($calendarResult)."</pre>");