我試圖通過PHP郵件()函數發送HTML內容。我不知道我的代碼有什麼問題。我嘗試了很多方法,花了數小時。但沒有任何成果。有誰能告訴我我的代碼有什麼問題嗎?PHP郵件()函數不發送HTML
<?php
$to = "[email protected]";
$today = date("Y/m/d");
$today = $today." 00:00";
$count_cash_inc = mysql_query("SELECT sum(income) as inc, sum(expense) as exp FROM journal_entry WHERE `date` >= '$today'");
$inc = mysql_fetch_array($count_cash_inc);
$income_c = $inc['inc'];
$epense_c = $inc['exp'];
$counter_cash = $income_c - $epense_c;
$subject = "Daily Report From Sri Sankalpa";
$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "CC: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = '<center><h1>Sri Sankalpa Daily Journal Report</h1>';
$message .= '<br><table><tr><td>Date</td><td>Total Income</td><td>Total Expense</td><td>Balance</td></tr>';
$message .= '<tr><td>'.date("d-m-Y").'</td><td>'.$income_c.'</td><td>'.$epense_c.'</td><td>'.$counter_cash.'</td></tr></table><br>';
$message .= '<p>To Know More... Please Click <strong><a target="_blank" href="http://srisankalpa.com/demo/journal_entry.php">HERE</a></strong></p></center>';
mail($to, $subject, $message, $headers);
?>
我試圖消除\ R,\ r \ n和改變字符集= UTF-8字符集來= ISO-8859-1。但沒有任何工作。尋找您的幫助。郵件以純文本形式發送完全沒有下面的行
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
使用[PHPmailer](http://phpmailer.worxware.com/)比簡單的'mail()更高級,並且容易追蹤錯誤 –
郵件可能被髮送,但gmail刪除它(垃圾郵件)。爲了防止它只是使用phpmailer –
添加此標頭'$頭。='內容類型:文本/ HTML; charset = iso-8859-1'。 「\ r \ n」;'見 –