2014-10-09 51 views
1

我使用PHP來發送ICS日曆邀請使用這個偉大的功能:iCal事件無論參數

function sendIcalEmail($firstname,$lastname,$email,$meeting_date,$meeting_name,$meeting_duration,$address,$details) { 

     $from_name = "Jason"; 
     $from_address = "[email protected]"; 
     $subject = "Showing"; //Doubles as email subject and meeting subject in calendar 
     $meeting_description = $details; 
     $meeting_location = $address; //Where will your meeting take place 
     $message=''; 

     //Convert MYSQL datetime and construct iCal start, end and issue dates 
     $meetingstamp = STRTOTIME($meeting_date . " UTC"); 
     $dtstart= GMDATE("Ymd\THis\Z",$meetingstamp); 
     $dtend= GMDATE("Ymd\THis\Z",$meetingstamp+$meeting_duration); 
     $todaystamp = GMDATE("Ymd\THis\Z"); 

     echo 'start:'.$dtstart.'<br><br>'; 
     echo 'end:'.$dtend.'<br><br>'; 

     //Create unique identifier 
     $cal_uid = DATE('Ymd').'T'.DATE('His')."-".RAND()."@mydomain.com"; 

     //Create Mime Boundry 
     $mime_boundary = "----Meeting Booking----".MD5(TIME()); 

     //Create Email Headers 
     $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/alternative; boundary=\"$mime_boundary\"\n"; 
     $headers .= "Content-class: urn:content-classes:calendarmessage\n"; 

     //Create Email Body (HTML) 
     $message .= "--$mime_boundary\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 '.$firstname.' '.$lastname.',</p>'; 
     //$message .= '<p>Here is my HTML Email/Used for Meeting Description</p>'; 
     $message .= "</body>\n"; 
     $message .= "</html>\n"; 
     $message .= "--$mime_boundary\n"; 

     //Create ICAL Content (Google rfc 2445 for details and examples of usage) 
     $ical = 'BEGIN:VCALENDAR 
    PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN 
    VERSION:2.0 
    METHOD:PUBLISH 
    BEGIN:VEVENT 
    ORGANIZER:MAILTO:'.$from_address.' 
    DTSTART:'.$dtstart.' 
    DTEND:'.$dtend.' 
    LOCATION:'.$meeting_location.' 
    TRANSP:OPAQUE 
    SEQUENCE:0 
    UID:'.$cal_uid.' 
    DTSTAMP:'.$todaystamp.' 
    DESCRIPTION:'.$meeting_description.' 
    SUMMARY:'.$subject.' 
    PRIORITY:5 
    CLASS:PUBLIC 
    END:VEVENT 
    END:VCALENDAR'; 

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

     //SEND MAIL 
     $mail_sent = @MAIL($email, $subject, $message, $headers); 

     IF($mail_sent)  { 
      RETURN TRUE; 
     } ELSE { 
      RETURN FALSE; 
     } 

    } 

在我的手機,我看到下面的日期/時間:

星期四2014年10月9日

從08:00至09:00

從12:00至13:00(GMT)

我的地方,並從參數如下:

start:20141009T120000Z 

    end:20141009T130000Z 

所以給我的08:00和09:00是意想不到的。但也許我錯過了一些東西。

+2

什麼是您的時區?您的程序可能會以UTC/GMT顯示原始時間,並會在您的時區中增加時間。 12-13 UTC與上午8-9點相同,日光 – Cheery 2014-10-09 03:26:22

+0

請作爲答案。因爲這是答案。 – 2014-10-09 03:30:54

回答

0

你的時區是什麼?您的程序可能會以UTC/GMT(字母Z - 時間戳中的Zulu)顯示原始時間,並會在您的時區中增加時間。 12:00 - 13:00 UTC的日照時間與東部時間上午8:00至9:00相同。在開始和結束時間設置正確的時區。