0
<?php
function sendIcalEvent($to_address, $startTime, $endTime, $subject, $description,  $location)
{
$from_name = 'ivan.k';
$from_address = 'ivan.k@cspl.com';
$to_name = "Ramya"; 
$domain = 'cspl.com';
//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/mixed; boundary=\"$mime_boundary\"\n";
// $headers .= "Content-type: text/calendar; method=REQUEST; charset=UTF-8\r\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";

//status / url / recurid /
$ical = 'BEGIN:VCALENDAR' . "\r\n" .
'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
// 'CALSCALE:GREGORIAN' . "\r\n" .
// 'METHOD:PUBLISH' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VTIMEZONE' . "\r\n" .
'TZID:Eastern Time' . "\r\n" .
'BEGIN:STANDARD' . "\r\n" .
'DTSTART:20091101T020000' . "\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:20090301T020000' . "\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="Eastern Time":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
'DTEND;TZID="Eastern Time":'.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);

if($mailsent){
return true;
} else {
return false;
}
}

我正在使用 php 通过邮件将日历请求发送到 Outlook。它具有 html 正文内容。在此 meeting.ics 将作为附件发送,但我希望将其作为日历请求发送,该请求应自动添加到日历中。如果我在标题中将内容类型指定为文本/日历,则 html 正文变为空。有人可以帮我一些代码吗?提前致谢

嗨,还有一个问题。当我将 $starttime 设置为“2013-01-23 13:00:00”时,它必须在 2013 年 1 月 23 日下午 1 点添加到日历中,但它会添加到 06:30下午 23 年 1 月 23 日。我希望它以 IST 格式发送。如何做到这一点。有什么建议吗?

4

3 回答 3

0

您需要添加Content-Disposition到您的消息部分:

尝试改变这一点:

$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';

对此:

$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';
$message .= 'Content-Disposition: attachment';
$message .= 'Content-Transfer-Encoding: base64';

不确定这项工作是否因为我没有测试过,它在每个邮件客户端上的行为可能不同。

于 2013-01-22T11:03:52.190 回答
0

尝试使用这个:

header("Content-type:text/calendar");
header('Content-Disposition: attachment; filename="'.$this->name.'.ics"');
于 2014-03-22T09:55:25.020 回答
0

除了 ics 附件,甚至可以在您的电子邮件正文中添加另一个正文部分,并带有以下标题。

$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n'; $message .= '内容传输编码:base64';

在这个body部分的内容中放ics文件内容。

这应该工作!

于 2013-02-06T13:08:09.187 回答