2012年3月23日 星期五

Email加上讀取回條

Email的讀取回條,

在程式上的做法是加上 Disposition-Notification-To 的header參數。

以下以PHP為範例:

ini_set("SMTP","msa.hinet.net");
ini_set("smtp_port","25");

$to = "aa@example.com";
$subject = "標題測試";
$body = "內容測試";
$from = "bb@example.com";
$reply_to_name = "reply name";
$reply_to_email = "bb@example.com";


$subject = '=?utf-8?B?' . base64_encode($subject) . '?=';
$body = chunk_split(base64_encode($body));
$reply_to = '=?utf-8?B?'. base64_encode($reply_to_name). '?=' . "<$reply_to_email>";
$add_head = "From:$from";
$add_head .= "\nReply-To:$reply_to";
$add_head .= "\nMIME-Version: 1.0";
$add_head .= "\nContent-Type: text/html; charset=utf-8";
$add_head .= "\nContent-Transfer-Encoding: base64";
$add_head .= "\nDisposition-Notification-To:$from";//要求已讀取回條

mail($to,$subject,$body,$add_head);

若對方的收信轉體有回覆回條的功能,且對方同意回覆回條,
就可以收到已讀取回條了。

沒有留言:

張貼留言