Php html邮件没有在html中显示

I am trying to send an html email. Mail is working properly but not going as html email and it is just displaying ".$message.". The data is coming from the mysql database.

My script is as follows:

$to       = $email;
$subject  = $subject;
$message  = "$message";

$htmlContent = '
<html>
<body>
".$message."
<br /><br />Regards<br /><b>TM</b>
</body>
</html>';
$headers  = 'From: myemail@gmail.com' . "
";
$headers .= 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=UTF-8' . "
";

if(mail($to, $subject, $htmlContent, $headers))
echo "Mail Sent";
else
echo "Problem sending email";

You have mixed single and double quotes. Use only one type when concatenating strings.

$htmlContent = "
<html>
<body>
".$message."
<br /><br />Regards<br /><b>RainbowCTM</b>
</body>
</html>";

To complete previous answer, there is a huge difference between single and double quotes:

  • Single quote not analyze characters inside, so if you did: echo '$message', it just display $message.
  • Double quotes analyze characters inside, so if you did: echo "$message", it displays the content of $message variable.

Finwe is totally right. Explanation: single quotes always take the string as it is without processing variables or metasigns like \t or .

just a hint in addition: try using only and not since there was a bug in some PHP-version that produced erros. even if this is not a problem at the moment, it might become one after an update (depending on your PHP-version).