我正在尝试通过PHP mail()函数发送HTML内容。 我不知道我的代码有什么问题。 我尝试了很多方法,花费了几个小时,但是没有成功。 请问有人能告诉我我的代码有什么问题吗?
<?php
$to = "shakthik92@gmail.com";
$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: info@srisankalpa.com\r\n";
$headers .= "Reply-To: info@srisankalpa.com\r\n";
$headers .= "CC: admin@srisankalpa.com\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 和将 charset=UTF-8 更改为 charset=iso-8859-1。但是都没有起作用。期待您的帮助。邮件发送完全是纯文本,不包含下面这行。
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail()
更先进,易于跟踪错误。 - Abdulla Nilam$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
并查看结果。 - Abdulla Nilam