1

Google vcalender ICS ファイルを作成し、PHP を使用して電子メールで送信します。

しかし、Google カレンダーに時刻が正しく表示されないという問題に直面しています。私の例では、時間を午前 01:00:00 (IST) として渡しましたが、ics ファイルのカレンダーをインポートすると、午前 12 時 (IST) が表示されます。

Google カレンダーの設定タイムゾーンを米国 (EST) に変更すると、時刻は午後 1 時 30 分 (EST) と表示されますが、午後 2 時 30 分 (EST) のはずです。

私のコードの何が問題になっていますか?

ics ファイルを生成して電子メールとして送信するための PHP コードは次のとおりです。

$user_timezone = dynamic timezone; // my timezone = Asia/Kolkata
    $demo_date = 2014-12-05;
    $demo_time = 01:00:00 AM;

    $meeting_date = $demo_date .' '.$demo_time;

    date_default_timezone_set($user_timezone);

    $date = date('Y-m-d H:i:s A', strtotime($meeting_date));

    // Event time stamp
    $timestamp = strtotime(date($meeting_date));

    // Event start date and end date
    $start_date = date('Ymd', strtotime($meeting_date)) ."T". date('H:i:s A', $timestamp);
    $end_date = date('Ymd', strtotime($meeting_date)) ."T". date('H:i:s A', $timestamp);

    //calender unique ID
    $cal_uid = date('Ymd').'T'.date('His')."-".rand();

    //Message send to Calender
    $ical = "BEGIN:VCALENDAR\n";
    $ical .= "VERSION:2.0\n";
    $ical .= "PRODID:-//Forest//Forest Inquiry v1.0//EN\n";
    $ical .= "CALSCALE:GREGORIAN\n";
    $ical .= "METHOD:PUBLISH\n";
    $ical .= "X-WR-CALNAME:Forest Inquiry\n";
    $ical .= "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n";
    $ical .= "BEGIN:VTIMEZONE\n";
    $ical .= "X-WR-TIMEZONE:{$user_timezone}\n";
    $ical .= "TZID:{$user_timezone}\n";
    $ical .= "TZURL:http://tzurl.org/zoneinfo-outlook/{$user_timezone}\n";
    $ical .= "X-LIC-LOCATION:{$user_timezone}\n";
    $ical .= "END:VTIMEZONE\n";
    $ical .= "BEGIN:VEVENT\n";
    $ical .= "DTSTAMP:".date('Ymd\THis\Z')."\n";
    $ical .= "DTSTART;TZID={$user_timezone}:{$start_date}\n";
    $ical .= "DTEND;TZID={$user_timezone}:{$end_date}\n";
    $ical .= "STATUS:CONFIRMED\n";
    $ical .= "SUMMARY:{$subject}\n";
    $ical .= "DESCRIPTION:{$meeting_description}\n";
    $ical .= "ORGANIZER;CN=Forest:MAILTO:info@Forest.com\n";
    $ical .= "CLASS:PUBLIC\n";
    $ical .= "CREATED:{$start_date}Z\n";
    $ical .= "LOCATION:{$meeting_location}\n";
    $ical .= "URL:\n";
    $ical .= "SEQUENCE:1\n";
    $ical .= "LAST-MODIFIED:".date('Ymd\THis\Z')."\n";
    $ical .= "UID:{$subject}-support@mysite.com\n";
    $ical .= "END:VEVENT\n";
    $ical .= "END:VCALENDAR";

    $file_name = 'XYZ'.$first_name;
    // Mail parameters
    $newline = "\r\n";
    $headers = "From:test\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: text/calendar; charset=utf-8; name=$file_name.ics; method=REQUEST".$newline;
    $headers .= "Content-Disposition: inline; filename=$file_name.ics".$newline;
    $headers .= "Content-Transfer-Encoding: 7bit";

    mail('testing@gmail.com', $subject, $ical, $headers);

ここに私のICSファイルがあります:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Forest//Forest Inquiry v1.0//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Forest Inquiry
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VTIMEZONE
TZID:Asia/Kolkata
TZURL:http://tzurl.org/zoneinfo-outlook/Asia/Kolkata
X-LIC-LOCATION:Asia/Kolkata
END:VTIMEZONE
BEGIN:VEVENT
DTSTAMP:20141205T104434Z
DTSTART;TZID=Asia/Kolkata:20141211T053000
DTEND;TZID=Asia/Kolkata:20141211T053000
STATUS:CONFIRMED
SUMMARY:Forest Inquiry by testing Testing
DESCRIPTION:First Name :testing\n
ORGANIZER;CN=Forest:MAILTO:info@Forest.com
CLASS:PUBLIC
CREATED:20141211T053000Z
LOCATION:At Forest
URL:
SEQUENCE:1
LAST-MODIFIED:20141205T104434Z
UID:Forest Inquiry by testing Testing-support@mysite.com
END:VEVENT
END:VCALENDAR
4

1 に答える 1