我正在使用以下代码将日历事件发送到Outlook。我面临时区问题。我将开始时间发送为晚上 8 点。但是,它设置了第二天凌晨 1:30。请检查下面的代码,并建议我如何发送时区与时间。
<?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:VCALENDARn
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//ENn
VERSION:2.0n
METHOD:REQUESTn
BEGIN:VEVENTn
ORGANIZER:MAILTO:organizer@domain.comn
DTSTAMP:".date('Ymd').'T'.date('His')."n
DTSTART:$dtStartn
DTEND:$dtEndn
TRANSP:OPAQUEn
SEQUENCE:0n
UID:".date('Ymd').'T'.date('His')."-".rand()."-domain.comn
SUMMARY:do something somewaren
DESCRIPTION: This is just a testn
PRIORITY:5n
X-MICROSOFT-CDO-IMPORTANCE:1n
CLASS:PUBLICn
END:VEVENTn
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 = "fromPerson@domain.com"; // Who the email is from
$email_subject = "Email test"; // The Subject of the email
$email_message = "this is a sample message nn next line nn next line"; // Message that the email has in it
$email_to = "toPerson@domain.com"; // 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.0n" .
"Content-Type: multipart/mixed;n" .
" boundary="{$mime_boundary}"";
$email_message .= "This is a multi-part message in MIME format.nn" .
"--{$mime_boundary}n" .
"Content-Type:text/html; charset="iso-8859-1"n" .
"Content-Transfer-Encoding: 7bitnn" .
$email_message . "nn";
$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: base64nn" .
$data . "nn" .
"--{$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!");
}
?>
RFC 5545 中有很多关于时区的信息。
例子:
DTSTART;TZID=America/New_York:19980119T020000
DTEND;TZID=America/New_York:19980119T030000
TZID=America/New_York:19980119T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
BEGIN:VTIMEZONE
TZID:America/New_York
LAST-MODIFIED:20050809T050000Z
BEGIN:STANDARD
DTSTART:20071104T020000
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20070311T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
END:DAYLIGHT
END:VTIMEZONE