Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring mime type for html-email

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?)?

like image 507
sica07 Avatar asked Nov 03 '09 09:11

sica07


People also ask

Where do I put MIME type in HTML?

Look for a <meta> element in the page source that gives the MIME type, for example <meta http-equiv="Content-Type" content="text/html"> . According to the standards, the <meta> element that specifies the MIME type should be ignored if there's a Content-Type header available.

What is MIME type in HTML?

A media type (also known as a Multipurpose Internet Mail Extensions or MIME type) indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

How do I enable MIME type?

In the Connections pane, go to the site, application, or directory for which you want to add a MIME type. In the Home pane, double-click MIME Types. In the MIME Types pane, click Add... in the Actions pane. In the Add MIME Type dialog box, add the file name extension and MIME type, and then click OK.

Is MIME type same as content-type?

content_type is an alias for mimetype. Historically, this parameter was only called mimetype, but since this is actually the value included in the HTTP Content-Type header, it can also include the character set encoding, which makes it more than just a MIME type specification.


4 Answers

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
like image 73
Konamiman Avatar answered Oct 18 '22 19:10

Konamiman


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>
like image 21
buddingprogrammer Avatar answered Oct 18 '22 19:10

buddingprogrammer


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!

like image 39
mbear Avatar answered Oct 18 '22 18:10

mbear


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 <[email protected]>, Kelly <[email protected]>';
$headers[] = 'From: Birthday Reminder <[email protected]>';
$headers[] = 'Cc: [email protected]';
$headers[] = 'Bcc: [email protected]';

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

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

like image 27
Julian Avatar answered Oct 18 '22 18:10

Julian