0

I am using the below code for sending Calendar events to Outlook. I am facing problem with Timezones. I am sending Start time as 8PM. But, it sets 1.30AM of next day. Please check the below code and suggest me how can i send TimeZones with Time.

       <?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:organizer@domain.com\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 = "fromPerson@domain.com"; // 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 = "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.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!");
} 

?>

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Kishore
  • 352
  • 1
  • 3
  • 19
  • Why not just do the timezone conversion to the start and end vales? Those are passed as GMT, so just add/subtract the number of hours you need to offset. – Mattt Oct 18 '13 at 21:27
  • @mjayt, Thanks for your response. Yes, I am doing same as you told. But the problem is The calendar alert shows in Correct time. But the allocation of event @ outlook calender in different time. I need to convert time automatically to users system Time. can you suggest anything? – Kishore Oct 18 '13 at 22:00
  • This might help http://stackoverflow.com/questions/7626114/ics-timezone-not-working – Mattt Oct 19 '13 at 01:50
  • @mjayt Thank you soo much.. The link which you provided is perfect for my requirement. Its working good. – Kishore Oct 21 '13 at 19:29

1 Answers1

0

There is a lot of info about timezone in RFC 5545.

Examples:

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
Community
  • 1
  • 1
Glavić
  • 42,781
  • 13
  • 77
  • 107