0
我使用下面的代码将日历事件发送到Outlook。我面临时区问题。我将发送时间设置为8PM。但是,它设定了第二天的上午1点30分。请检查下面的代码,并建议我如何发送TimeZones与时间。通过php发送日历事件的TimeZone代码
<?php
$dtStart = '20131019T131415Z';//yyyymmddThhmmssZ
$dtEnd = '20131019T151617Z';
//--------------------
//create text file
$ourFileName = "temp_files/calendar.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file1");
fclose($ourFileHandle);
//
//edit temp file
$myFile = "temp_files/calendar.txt";
$fh = fopen($myFile, 'w') or die("can't open file2");
$stringData = "
BEGIN:VCALENDAR\n
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN\n
VERSION:2.0\n
METHOD:REQUEST\n
BEGIN:VEVENT\n
ORGANIZER:MAILTO:[email protected]\n
DTSTAMP:".date('Ymd').'T'.date('His')."\n
DTSTART:$dtStart\n
DTEND:$dtEnd\n
TRANSP:OPAQUE\n
SEQUENCE:0\n
UID:".date('Ymd').'T'.date('His')."-".rand()."-domain.com\n
SUMMARY:do something someware\n
DESCRIPTION: This is just a test\n
PRIORITY:5\n
X-MICROSOFT-CDO-IMPORTANCE:1\n
CLASS:PUBLIC\n
END:VEVENT\n
END:VCALENDAR";
fwrite($fh, $stringData);
fclose($fh);
//email temp file
$fileatt = "temp_files/calendar.txt"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "ical.ics"; // Filename that will be used for the file as the attachment
$email_from = "[email protected]"; // Who the email is from
$email_subject = "Email test"; // The Subject of the email
$email_message = "this is a sample message \n\n next line \n\n next line"; // Message that the email has in it
$email_to = "[email protected]"; // Who the email is too
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>
为什么不只是做时区转换的开始和结束瓦莱斯?这些传递格林尼治标准时间,所以只需加/减你需要抵消的小时数。 – Mattt
@mjayt,谢谢你的回应。是的,我跟你说的一样。但问题是日历警报显示在正确的时间。但在不同的时间分配event @ outlook日历。我需要将时间自动转换为用户系统时间。你能提出什么建议吗? – Kishore
这可能有助于http://stackoverflow.com/questions/7626114/ics-timezone-not-working – Mattt