14

I want to create a html email and I've read a lot about how to do it. There is one piece of information I can't find. How should I declare the mime type? I tried with:

meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

but it doesn't work.

Later edit:
I am trying to set the content-type of the mail to text/html but I don't know how. All this when writing from a regular email client. I have to declare it in the mail body? Or in the mail header (if so, how do I o it?)?

Stefan
  • 14,530
  • 4
  • 55
  • 62
sica07
  • 4,896
  • 8
  • 35
  • 54
  • 1
    What do you mean by "it doesn't work"? Do you get some error message? Do non-ANSI character look broken? Do your mail recipients see the HTML source instead of the rendered HTML? ... – Heinzi Nov 03 '09 at 09:35
  • 1
    It displays as a plain text – sica07 Nov 03 '09 at 10:11

4 Answers4

38

Are you trying to set the content-type declaration within the message header sent to the mail server? If so, you should set it this way, in a line itself:

Content-Type: text/html; charset=UTF-8
Konamiman
  • 49,681
  • 17
  • 108
  • 138
  • How can I do that, when I am in a normal mail client, as gmail,or yahoo? – sica07 Nov 03 '09 at 10:50
  • 1
    You can't. I've never seen a webmail client that allows custom HTML input (and rarely seen a desktop client). – Quentin Nov 03 '09 at 10:53
  • If you want to insert custom headers, then you'd need to write your own client. That's probably not worth doing, unless you have some very specific need, such as testing an SMTP server. – james.garriss Aug 26 '13 at 18:23
6

The end tag for meta tag is used only in xhtml/xml. If you are using html, you should use it inside <head> tags like:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
Mirza Obaid
  • 1,707
  • 3
  • 23
  • 35
4

Basically email clients ignore any META tags with Content type in them (at least as of 2013-10-17).

You need to set a the content type declaration in a special header in the email server.

More information about this issue can be found at http://www.emailonacid.com/blog/details/C13/the_importance_of_content-type_character_encoding_in_html_emails

If this makes no sense to you, then I'm afraid you're out of luck. The only reliable solution I've found is to convert any special characters to their HTML entity equivalent. The link above has a link to a tool that does this for you.

Hope that helps!

mbear
  • 121
  • 1
  • 3
2

This applies to php:

// To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';

// Additional headers
$headers[] = 'To: Mary <mary@example.com>, Kelly <kelly@example.com>';
$headers[] = 'From: Birthday Reminder <birthday@example.com>';
$headers[] = 'Cc: birthdayarchive@example.com';
$headers[] = 'Bcc: birthdaycheck@example.com';

// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));

http://php.net/manual/en/function.mail.php#example-4180

Julian
  • 4,396
  • 5
  • 39
  • 51