<?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.It有html正文内容。在这里,meeting.ics将作为附件发送,但我希望将其作为日历请求发送,应自动添加到日历。如果我在标题中将内容类型作为文本/日历提供,则html正文变为空。任何人都可以帮我一些代码吗? 提前致谢
你有另外一个问题。当我将$ starttime设置为“2013-01-23 13:00:00”时,它必须在2013年1月23日下午1点被添加到日历中,但它被添加到下午06:30 23-01-23。我希望它以IST格式发送如何做到这一点。一些sugessions?
答案 0 :(得分: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';
不确定这项工作是否导致我没有经过测试,并且每个邮件客户端的行为都不同。
答案 1 :(得分:0)
除了ics附件,甚至还会在您的电子邮件正文中添加另一个正文部分,并附上以下标题。
$ message。='Content-Type:text / calendar; name =“meeting.ics”; method = REQUEST \ n'; $ message。='Content-Transfer-Encoding:base64';
在本机构部分的内容中放入了ics文件内容。
这应该有用!!
答案 2 :(得分:0)
尝试使用它:
header("Content-type:text/calendar");
header('Content-Disposition: attachment; filename="'.$this->name.'.ics"');