7

Trying to send a html email via mail(), however gmail just displays the email as plain text, no mark up, eg:

mail("blah@blah.com", "subject", "<i>Italic Text</i>");

just appears as

<i>Italic Text</i>

Any ideas?

peterh
  • 11,875
  • 18
  • 85
  • 108
DexCurl
  • 1,683
  • 5
  • 26
  • 38
  • possible duplicate of [Use HTML formatting in email sent from PHP](http://stackoverflow.com/questions/4971322/use-html-formatting-in-email-sent-from-php) – mario Apr 19 '11 at 11:09
  • possible duplicate of [Php mail: how to send html?](http://stackoverflow.com/questions/4897215/php-mail-how-to-send-html) – mario Apr 19 '11 at 11:10
  • possible duplicate of [Include html in email](http://stackoverflow.com/questions/4916477/include-html-in-email) – mario Apr 19 '11 at 11:11
  • possible duplicate of [How to add html codes in email?](http://stackoverflow.com/questions/5055757/how-to-add-html-codes-in-email) – mario Apr 19 '11 at 11:12
  • You can't use HTML in the message subject. – Álvaro González Apr 19 '11 at 11:16
  • sorry, my apologies, didn't notice I skipped the subject parameter – DexCurl Apr 19 '11 at 11:31

5 Answers5

15

You have to specify that the contents of the mail is HTML:

mail("blah@blah.com", "subject", "<i>Italic Text</i>", "Content-type: text/html; charset=iso-8859-1");
user254875486
  • 11,190
  • 7
  • 36
  • 65
7

See example 4 on this page:

http://php.net/manual/en/function.mail.php

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
3

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("blah@blah.com", $msg, $headers);
Ant
  • 3,877
  • 1
  • 15
  • 14
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

bluefoot
  • 10,220
  • 11
  • 43
  • 56
1

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.

user123
  • 51
  • 5