HTML not formatting in mail function
I am using the following code:
$message = "Hi ".$user. ",\r\rThe following names are on the guestlist for <b>".$night. "</b> on ".$date2.":\r\r". $user ."<br>". implode(", ", $names). "\r\rThank you for using Guestvibe."; mail($email, "Your Guestvibe list", $message);
The carriage returns in PHP are working fine, but neither the <b> or <br> tags are coming out. Is it just my mail client (Apple Mail) playing up, or is there a fix for this?
You are sending the e-mail as text only not HTML, I believe you need to set these headers:
$headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
as in example #4 of the docs.
PHP's mail function sends plaintext mail by default.
See the nr.4 example at mail's manual page for the correct way to send HTML mail.
You need to add your headers:
$headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($email, "Your Guestvibe list", $message, $headers);
You should firstly wrap the whole message into:
<html><head></head><body> msg </body></html>
Plus headers from m.edmondson post.