Question:
Users need assistance sending HTML emails using PHP's mail() function. Despite setting the "Content-type" header to "text/html," the email body only contains plain text instead of formatted HTML.
Answer:
To resolve this issue, it's essential to:
$header = "MIME-Version: 1.0\r\n"; $header .= "Content-type: text/html; charset: utf8\r\n";
<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> ... ... ...
Example Code:
$header = "MIME-Version: 1.0\r\n"; $header .= "Content-type: text/html; charset: utf8\r\n"; $body = "This text should be red
"; $success = mail($to, $subject, $body, $header); if ($success) { echo "Sent HTML email successfully.
"; } else { echo "Error sending HTML email.
"; }
The above is the detailed content of How to Send HTML Emails with PHP's mail() Function?. For more information, please follow other related articles on the PHP Chinese website!