How do I send HTML formatted mail using PHP?
Solution 1
You have to specify that the contents of the mail is HTML:
mail("[email protected]", "subject", "<i>Italic Text</i>", "Content-type: text/html; charset=iso-8859-1");
Solution 2
See example 4 on this page:
http://php.net/manual/en/function.mail.php
Solution 3
I believe you must set the content-type
to text/html
in your headers.
Something like the string "Content-type:text/html"
Where to "insert" this header? Take a look at the function reference at http://php.net/manual/en/function.mail.php
Solution 4
You need to have a properly formed html doc:
$msg = "<html><head></head><body><i>Italic Text</i></body></html>";
Edit:
And send headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail("[email protected]", $msg, $headers);
Solution 5
In order for it to be properly interpreted, you must also set the headers in the email, especially:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
You should also set the other usual headers. The message can finally be sent like this:
mail($to, $subject, $message, $headers);
You should refer to the php manual mail page for more information.
DexCurl
Updated on October 29, 2020Comments
-
DexCurl over 3 years
Trying to send a html email via mail(), however gmail just displays the email as plain text, no mark up, eg:
mail("[email protected]", "subject", "<i>Italic Text</i>");
just appears as
<i>Italic Text</i>
Any ideas?
-
mario about 13 yearspossible duplicate of Use HTML formatting in email sent from PHP
-
mario about 13 yearspossible duplicate of Php mail: how to send html?
-
mario about 13 yearspossible duplicate of Include html in email
-
mario about 13 yearspossible duplicate of How to add html codes in email?
-
Álvaro González about 13 yearsYou can't use HTML in the message subject.
-
DexCurl about 13 yearssorry, my apologies, didn't notice I skipped the subject parameter
-