简体   繁体   English

使用 php 将 .ics 文件作为日历发送而不是作为附件发送

[英]sending .ics file as calender not as attachment using php

<?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;
}
}

I am sending the calender request to outlook through mail using php.It have the html body content.In this the meeting.ics is going as a attachment but i want that to be send as calender request that should added automatically to the calender .我正在使用 php 通过邮件将日历请求发送到 Outlook。它具有 html 正文内容。在此 meeting.ics 将作为附件发送,但我希望将其作为日历请求发送,该请求应自动添加到日历中。 if i give content type as text/calender in header the html body becomes empty.Can anyone help me with some code?如果我在标题中将内容类型指定为文本/日历,则 html 正文变为空。有人可以帮我一些代码吗? Thanks in advance提前致谢

Hi got another one problem.when i set the $starttime as "2013-01-23 13:00:00" it have to get added to the calender at 01 PM on 23-01-2013 but it is added to 06:30 PM on 23-01-23.I want it to send at IST format how to do that.any sugessions?嗨,还有一个问题。当我将 $starttime 设置为“2013-01-23 13:00:00”时,它必须在 2013 年 1 月 23 日下午 1 点添加到日历中,但它被添加到 06:30下午 23 年 1 月 23 日。我希望它以 IST 格式发送。如何做到这一点。有什么建议吗?

You need to add Content-Disposition to you message part:您需要将Content-Disposition添加到您的消息部分:

Try to change this:尝试改变这一点:

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

To this:对此:

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

Not sure that this work cause i didn't tested and it can behave differently on each mail client.不确定这项工作是否因为我没有测试过,它在每个邮件客户端上的行为可能不同。

Along with the ics attachment even add another body part to your email body with following headers.除了 ics 附件,甚至可以在您的电子邮件正文中添加另一个正文部分,并带有以下标题。

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

In the content of this body part put the ics file content.在这个body部分的内容中放ics文件内容。

This should work!!这应该工作!

Try to use this:尝试使用这个:

header("Content-type:text/calendar");
header('Content-Disposition: attachment; filename="'.$this->name.'.ics"');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM