Sending HTML Email Using mail
suggest change<?php
$to = 'recipient@example.com';
$subject = 'Sending an HTML email using mail() in PHP';
$message = '<html><body><p><b>This paragraph is bold.</b></p><p><i>This text is italic.</i></p></body></html>';
$headers = implode("\r\n", [
"From: John Conde <webmaster@example.com>",
"Reply-To: webmaster@example.com",
"X-Mailer: PHP/" . PHP_VERSION,
"MIME-Version: 1.0",
"Content-Type: text/html; charset=UTF-8"
]);
mail($to, $subject, $message, $headers);
This is not much different from sending a plain text email. The key differences are that the body is structured like an HTML document and that two additional headers must be included so the email client knows to render the email as HTML. They are:
- MIME-Version: 1.0
- Content-Type: text/html; charset=UTF-8
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents