2012-12-28 167 views
2

我想通過我的php代碼實現日曆請求郵件。我的代碼是這樣的:通過郵件發送日曆請求

$to = "[email protected]"; 
$subject = "Training Registration"; 
$message = "Thank you for participating in the Technical Certification training program."; 
$location = "Conf"; 
//================== 
$headers = "Content-Type:text/calendar; Content-Disposition: inline; charset=utf-8;"; 
$headers .= "Content-Type: text/plain;charset=utf-8"; 
$messaje = "BEGIN:VCALENDAR"; 
$messaje .= "VERSION:2.0"; 
$messaje .= "PRODID:PHP"; 
$messaje .= "METHOD:REQUEST"; 
$messaje .= "BEGIN:VEVENT"; 
$messaje .= "DTSTART:20121223T171010Z"; 
$messaje .= "DTEND:20121223T191010Z"; 
$messaje . "DESCRIPTION: You have registered for the class"; 
$messaje .= "SUMMARY:Technical Training"; 
$messaje .= "ORGANIZER; CN=\"Corporate\":mailto:[email protected]"; 
$messaje .= "Location:" . $location . ""; 
$messaje .= "UID:040000008200E00074C5B7101A82E00800000006FC30E6 C39DC004CA782E0C002E01A81\n"; 
$messaje .= "SEQUENCE:0\n"; 
$messaje .= "DTSTAMP:".date('Ymd').'T'.date('His')."\n"; 
$messaje .= "END:VEVENT\n"; 
$messaje .= "END:VCALENDAR\n"; 
$headers .= $messaje; 
mail($to, $subject, $message, $headers); 

通過此代碼我收到了郵件,但沒有按日曆請求格式。此外,郵件已連同附件「Training Registration.ics」文件一起轉發。 我需要接受,暫定,拒絕,建議新的時間,日曆選項以及郵件。 請指導我如何做到這一點。 謝謝。

+0

不確定我會在這裏發佈代碼中看起來有效的電子郵件地址。 – PeterJ

+0

考慮使用PHPMailer或SwiftMailer等現代PHP郵件庫來處理附件。正如你現在看到的,滾動你自己的MIME是一個*痛苦*。 – Charles

回答

2
$headers = 'Content-Type:text/calendar; Content-Disposition: inline; charset=utf-8;\r\n'; 

這裏,嘗試單引號改爲雙引號(「=>」)

這是因爲丁格爾報價會逃跑\ r和\ n
Reference

更新
最後,我在下面做了一些建議,並改變了標題,至少它在我的工作方面起作用了。

$to = "[email protected]"; 
$subject = "Training Registration"; 
$message = "Thank you for participating in the Technical Certification training program.\r\n\r\n"; 
$location = "Conf"; 
//================== 
$headers .= "MIME-version: 1.0\r\n"; 
$headers .= "Content-class: urn:content-classes:calendarmessage\r\n"; 
$headers .= "Content-type: text/calendar; method=REQUEST; charset=UTF-8\r\n"; 
$messaje = "BEGIN:VCALENDAR\r\n"; 
$messaje .= "VERSION:2.0\r\n"; 
$messaje .= "PRODID:PHP\r\n"; 
$messaje .= "METHOD:REQUEST\r\n"; 
$messaje .= "BEGIN:VEVENT\r\n"; 
$messaje .= "DTSTART:20121223T171010Z\r\n"; 
$messaje .= "DTEND:20121223T191010Z\r\n"; 
$messaje .= "DESCRIPTION: You have registered for the class\r\n"; 
$messaje .= "SUMMARY:Technical Training\r\n"; 
$messaje .= "ORGANIZER; CN=\"Corporate\":mailto:[email protected]\r\n"; 
$messaje .= "Location:" . $location . "\r\n"; 
$messaje .= "UID:040000008200E00074C5B7101A82E00800000006FC30E6 C39DC004CA782E0C002E01A81\r\n"; 
$messaje .= "SEQUENCE:0\r\n"; 
$messaje .= "DTSTAMP:".date('Ymd').'T'.date('His')."\r\n"; 
$messaje .= "END:VEVENT\r\n"; 
$messaje .= "END:VCALENDAR\r\n"; 
$message .= $messaje; 
mail($to, $subject, $message, $headers); 
+0

實際上,上面的答案假設代碼可以發送日曆〜_〜我不知道如何通過電子郵件發送日曆@@ a –

+0

將單引號更改爲雙引號後,我得到以下問題: 組織者; CN = 「公司」 至:mailto:[email protected] 地點: UID:040000008200E00074C5B7101A82E00800000006FC30E6 C39DC004CA782E0C002E01A81順序:0 DTSTAMP:20121228T002344 END:VEVENT END:VCALENDAR 感謝您參與技術認證培訓計劃。 同樣在標題部分,我收到了另一條消息,如「此消息中的額外換行符已被刪除。」我沒有收到該電子郵件的任何「接受」鏈接或Tentavive鏈接。 – phpdeveloper

+0

你的代碼從哪裏來?我不知道如何通過電子郵件發送日曆,並且現在沒有時間做研究,因爲我在辦公室:-)但是,我的下一個建議是檢查是否應該在$標題中放置$ messaje –