提问人:Khurshid 提问时间:11/14/2023 最后编辑:ADysonKhurshid 更新时间:11/14/2023 访问量:31
尝试将事件添加到Outlook日历,但无法正常工作
Trying to Add Event to Outlook Calendar but its not working
问:
'嗨,一切,从过去的 2-3 天开始,我尝试了许多方法将事件添加到我的 Outlook 日历,但它没有分配,我收到了具有不同布局的电子邮件,这意味着它也显示了 HTML 脚本。我不知道我做错了什么。需要您的帮助。
----我的PHP代码-----
$domain = 'dopasi.org';
$from_name = 'FromName'; // From
$from_address = '[email protected]'; // From Email
$to_name = 'ToName';
$to_address = '[email protected]';
$startTime = '13/11/2023' . ' ' . '11:00';
$endTime = '13/11/2023' . ' ' . '12:00';
$subject = 'Meeting Title';
$description = 'Meeting Description';
$location = "TestCity";
//Create Email Headers
$mime_boundary = "----Meeting Booking----".MD5(TIME());
$headers = "From: ".$from_name." <".$from_address.">\n";
$headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
$headers .= "Content-class: urn:content-classes:calendarmessage\n";
//Create Email Body (HTML)
$message = "--$mime_boundary\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "<html>\n";
$message .= "<body>\n";
$message .= '<p>Dear '.$to_name.',</p>';
$message .= '<p>'.$description.'</p>';
$message .= "</body>\n";
$message .= "</html>\n";
$message .= "--$mime_boundary\r\n";
$ical = 'BEGIN:VCALENDAR' . "\r\n" .
'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VTIMEZONE' . "\r\n" .
'TZID:Asia/Karachi' . "\r\n" .
'BEGIN:STANDARD' . "\r\n" .
'DTSTART:20231114T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" .
'TZOFFSETFROM:-0400' . "\r\n" .
'TZOFFSETTO:-0500' . "\r\n" .
'TZNAME:EST' . "\r\n" .
'END:STANDARD' . "\r\n" .
'BEGIN:DAYLIGHT' . "\r\n" .
'DTSTART:20231114T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" .
'TZOFFSETFROM:-0500' . "\r\n" .
'TZOFFSETTO:-0400' . "\r\n" .
'TZNAME:EDST' . "\r\n" .
'END:DAYLIGHT' . "\r\n" .
'END:VTIMEZONE' . "\r\n" .
'BEGIN:VEVENT' . "\r\n" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."@".$domain."\r\n" .
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
'DTSTART;TZID="Asia/Karachi":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
'DTEND;TZID="Asia/Karachi":'.date("Ymd\THis", strtotime($endTime)). "\r\n" .
'TRANSP:OPAQUE'. "\r\n" .
'SEQUENCE:1'. "\r\n" .
'SUMMARY:' . $subject . "\r\n" .
'LOCATION:' . $location . "\r\n" .
'CLASS:PUBLIC'. "\r\n" .
'PRIORITY:5'. "\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";
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST'."\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $ical;
$mailsent = mail($to_address, $subject, $message, $headers);
echo ($mailsent) ? 'Success' : 'Failed';
结果 - 收到的电子邮件
`------Meeting Booking----fcf0f13b816a3795030bbfc724382b1d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<html>
<body>
<p>Dear ToName,</p><p>Meeting Description</p></body> </html> ------Meeting Booking----fcf0f13b816a3795030bbfc724382b1d
Content-Type: text/calendar; name="meeting.ics";method=REQUEST
Content-Transfer-Encoding: 8bit
BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN
VERSION:2.0
METHOD:REQUEST
BEGIN:VTIMEZONE
TZID: Asia/Karachi
BEGIN:STANDARD
DTSTART:20231114T020000
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20231114T020000
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDST
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
ORGANIZER;CN="fromName":MAILTO:[email protected]
ATTENDEE;CN="toName";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:toEmail#gmail.com
LAST-MODIFIED:20231114T112000
UID:[email protected]
DTSTAMP:20231114T112000
DTSTART;TZID="Asia/Karachi":19700101T050000
DTEND;TZID="Asia/Karachi":19700101T050000
TRANSP:OPAQUE
SEQUENCE:1
SUMMARY: Meeting Title
LOCATION: TestCity
CLASS:PUBLIC
PRIORITY:5
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION: Reminder
END:VALARM
END:VEVENT
END:VCALENDAR`
------------------这是我在电子邮件中收到的内容,事件未添加到日历----------------中
答:
0赞
Dmitry Streblechenko
11/14/2023
#1
发送到 Outlook 时,请确保您的邮件具有 .可以使用 iCal 数据中的字段(带有属性 = )添加 HTML。text/calendar
X-ALT-DESC
FMTTYPE
text/html
下一个:将静态概览日添加到日历
评论