2014-09-18 4 views
1

본 사이트의 코스 등록자에게 이메일을 보내려합니다. 한 번 완벽하게 작동 한이 PHP 코드를 발견 한 후 전혀 작동하지 않기로 결정했습니다.PHP로 회의 초대 및 HTML 이메일 보내기

기본적으로 사용자에게 전자 메일을 보내고 정상적인 메일은 완벽하지만 캘린더 일정은 Outlook 일정에 표시되지 않습니다. 여기

나는 코드를 사용하고 있습니다 :

<?php 

function sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime,  
$subject, $description, $location) 
{ 

$domain = 'example.com'; 

//Create Email Headers 
$mime_boundary = "----THIS WILL WORK!!!----".MD5(TIME()); 

$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\r\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 '.$to_name.',</p>'; 
$message .= '<p>'.$description.'</p>'; 
$message .= "</body>\n"; 
$message .= "</html>\n"; 
$message .= "--$mime_boundary\r\n"; 

$ical = 'BEGIN:VCALENDAR' . "\r\n" . 
'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" . 
'VERSION:2.0' . "\r\n" . 
'METHOD:REQUEST' . "\r\n" . 
'BEGIN:VTIMEZONE' . "\r\n" . 
'TZID:Eastern Time' . "\r\n" . 
'BEGIN:STANDARD' . "\r\n" . 
'DTSTART:20091101T020000' . "\r\n" . 
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" . 
'TZOFFSETFROM:-0400' . "\r\n" . 
'TZOFFSETTO:-0500' . "\r\n" . 
'TZNAME:EST' . "\r\n" . 
'END:STANDARD' . "\r\n" . 
'BEGIN:DAYLIGHT' . "\r\n" . 
'DTSTART:20090301T020000' . "\r\n" . 
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" . 
'TZOFFSETFROM:-0500' . "\r\n" . 
'TZOFFSETTO:-0400' . "\r\n" . 
'TZNAME:EDST' . "\r\n" . 
'END:DAYLIGHT' . "\r\n" . 
'END:VTIMEZONE' . "\r\n" . 
'BEGIN:VEVENT' . "\r\n" . 
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" . 
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" . 
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" . 
'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."@".$domain."\r\n" . 
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" . 
'DTSTART;TZID="Eastern Time":'.date("Ymd\THis", strtotime($startTime)). "\r\n" . 
'DTEND;TZID="Eastern Time":'.date("Ymd\THis", strtotime($endTime)). "\r\n" . 
'TRANSP:OPAQUE'. "\r\n" . 
'SEQUENCE:1'. "\r\n" . 
'SUMMARY:' . $subject . "\r\n" . 
'LOCATION:' . $location . "\r\n" . 
'CLASS:PUBLIC'. "\r\n" . 
'PRIORITY:5'. "\r\n" . 
'BEGIN:VALARM' . "\r\n" . 
'TRIGGER:-PT15M' . "\r\n" . 
'ACTION:DISPLAY' . "\r\n" . 
'DESCRIPTION:Reminder' . "\r\n" . 
'END:VALARM' . "\r\n" . 
'END:VEVENT'. "\r\n" . 
'END:VCALENDAR'. "\r\n"; 
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n'; 
$message .= "Content-Transfer-Encoding: 8bit\n\n"; 
$message .= $ical; 

$mailsent = mail($to_address, $subject, $message, $headers); 

return ($mailsent)?(true):(false); 
} 

$from_name = "from Name";   
$from_address = "from Address";   
$to_name = "to Name";   
$to_address = "[email protected]";   
$startTime = "11/09/2014 18:00:00";   
$endTime = "11/09/2014 19:00:00";   
$subject = "I HOPE THIS WORKS";   
$description = "I REALLY HOPE THIS WORKS";   
$location = "Joe's House"; 
sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject,  
$description, $location); 
?> 

내 질문은 : 거기 어떤 잘못 내 코드와 내가 그것을 해결하기 위해 할 수있는 그렇다면 볼 수?

답변

-1

사용이 :

$startTime = "11-09-2014 18:00:00";   
$endTime = "11-09-2014 19:00:00";