我正在尝试使用 iCal 通过电子邮件发送邀请。我的电子邮件发送工作正常,但我没有正确收到 iCal 附件。以下是我处理电子邮件发送的 php 函数。
function sendIcalEmail($firstname,$lastname,$email,$meeting_date,$meeting_name,$meeting_duration) {
$from_name = "Sampath";
$from_address = "my email";
$subject = "Meeting Booking"; //Doubles as email subject and meeting subject in calendar
$meeting_description = "Here is a brief description of my meeting.";
$meeting_location = "My Office"; //Where will your meeting take place
//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");
//Create unique identifier
$cal_uid = date('Ymd').'T'.date('His')."-".rand()."@example.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\n".
"PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN\n".
"VERSION:2.0\n".
"METHOD:PUBLISH\n".
"BEGIN:VEVENT\n".
"ORGANIZER:MAILTO:".$from_address."\n".
"DTSTART:".$dtstart."\n".
"DTEND:".$dtend."\n".
"LOCATION:".$meeting_location."\n".
"TRANSP:OPAQUE\n".
"SEQUENCE:0\n".
"UID:".$cal_uid."\n".
"DTSTAMP:".$todaystamp."\n".
"DESCRIPTION:".$meeting_description."\n".
"SUMMARY:".$subject."\n".
"PRIORITY:5\n".
"CLASS:PUBLIC\n".
"END:VEVENT\n".
"END:VCALENDAR";
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST;charset=utf-8\n';
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $ical;
//SEND MAIL
require_once "./swiftmailer/swift_required.php";
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('my email')
->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
$sendMessage = Swift_Message::newInstance('Meeting Invitation')
->setFrom(array($from_address => 'Sampath B. Herath'))
->setTo(array($email))
->setBody($message);
$result = $mailer->send($sendMessage);
if($result) {
return true;
} else {
return false;
}
}
以下是我在结果电子邮件中可以看到的内容。
------Meeting Booking----2a43c2697329a93848be0ba81582a3cb
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<html>
<body>
<p>Dear Sampath Herath,</p><p>Here is my HTML Email / Used for Meeting Description</p> </body>
</html>
------Meeting Booking----2a43c2697329a93848be0ba81582a3cb
Content-Type: text/calendar;name="meeting.ics";method=REQUEST;charset=utf- 8\nContent-Type: text/calendar;name="meeting.ics";method=REQUEST\nContent-Transfer- Encoding: 8bit
BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
ORGANIZER:MAILTO:sampath@orangehrm.us.com
DTSTART:20130819T134000Z
DTEND:20130819T144000Z
LOCATION:My Office
TRANSP:OPAQUE
SEQUENCE:0
UID:20130819T131345-988483816@example.com
DTSTAMP:20130819T074345Z
DESCRIPTION:Here is a brief description of my meeting.
SUMMARY:Meeting Booking
PRIORITY:5
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR
我的代码的确切问题是什么?