2012-10-04 25 views
2

我想向用戶發送icalendar,以便他們可以在Outlook中打開這些ics文件並保存約會。我使用的郵件是'phpmailer.php'。icalendar和phpmailer.php

問題是它在郵件正文中發送html格式的html。這裏是我的代碼


$text=" 
BEGIN:VCALENDAR 
VERSION:1.0 
BEGIN:VEVENT 
CATEGORIES:MEETING 
STATUS:TENTATIVE 
DTSTART:".$startDateTime." 
DTEND:".$endDateTime." 
SUMMARY:Interview for the candidate".$cname." 
DESCRIPTION:".$message." 
CLASS:PRIVATE 
END:VEVENT 
END:VCALENDAR"; 

$mail->SetFrom('[email protected]', 'xxxx'); 
$mail->IsSMTP(); 
$mail->Host = "smtp.mail.yahoo.com"; 

$mail->SMTPAuth = true; 
$mail->Username = '[email protected]'; 
$mail->Password = 'xxxxx'; 


$mail->AddAddress($addresses[$i]); 
$mail->Subject = "Interview schedule of Candidate"; 

    $headers = "From: Sender\n"; 
     $headers .= "Reply-To: [email protected]\n"; 
     $headers .= "MIME-Version: 1.0\n"; 
     $headers .= "Content-Type: text/calendar; method=REQUEST; charset=utf-8\n"; 
     $headers .= "Content-Transfer-Encoding: 8bit\n"; 
     $headers .= "Content-class: urn:content-classes:calendarmessage\n"; 
$mail->Body=$body; 

if(!$mail->Send($headers,$body)) 
{ 
     echo "Mailer Error: " . $mail->ErrorInfo; 
} 
else 
{ 
    echo "Message sent!"; 
} 


請讓我知道我的代碼有什麼問題。 在此先感謝

+2

你爲什麼不把它作爲附件發送? – Nelson

+0

謝謝@納爾遜,我用附件:) –

+0

@Nelson你有什麼想法,我怎麼能實現與zend_mail相同。 [鏈接](http://stackoverflow.com/questions/17646307/sending-ical-through-zend-mail) –

回答

2

你也可以嘗試:

$mail->IsHTML(FALSE); 
5

以下解決方案爲我工作:

$mail->Subject = $name; 
$mail->Body = $description; 
$mail->AltBody = $body; // in your case once more the $text string 
$mail->Ical = $message; // ical format, in your case $text string 
1

該解決方案爲我工作。 without attachemnt

$mail->AddStringAttachment("my_content_here", "meeting.ics", "7bit", "text/calendar; charset=utf-8; method=REQUEST");