我使用PHP mail()函數發送郵件。郵件標題無法正常工作。PHP郵件標題無法正常工作
$charset = mb_detect_encoding($message);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: '.$from . "\r\n";
$headers .= 'Content-type: text/html; charset='.$charset . "\r\n";
$headers .= 'Reply-To: '.$from . "\r\n";
$headers .= 'X-Mailer: php';
在上面的代碼中,唯一的第一行被解析,後面的4行顯示在消息正文中。 「From」沒有設置。
$charset = mb_detect_encoding($message);
$headers = 'From: '.$from . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset='.$charset . "\r\n";
$headers .= 'Reply-To: '.$from . "\r\n";
$headers .= 'X-Mailer: php';
在上面的代碼中,「從」和「MIME」線被正確地分析,但後來3行示出了在消息主體中。
GMail正在接收它。
爲什麼你混合單引號和雙引號?使用任何一個。 – Rikesh
試試$ headers。='Content-type:text/html; charset = iso-8859-1'。爲 「\ r \ n」 個; –
@Rikesh,單引號或雙引號不是問題。 – Sithu