`嗨一切,从过去的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`
型
--这是我在电子邮件中收到的,事件未添加到日历中-`
1条答案
按热度按时间enyaitl31#
发送到Outlook时,请确保您的邮件具有
text/calendar
类型的单个部分。可以在您的iCal数据中使用X-ALT-DESC
字段(具有FMTTYPE
属性=text/html
)添加HTML。