I’m trying to render html in an email and even after searching the web, I am still a little confused.. Basically I would like to have say a box(div) with a background color display in the email. I’m sending the email using the php mail() function and trying to set the message body to a string such as: "<div style='background:black;'>Test</div>", but instead of rendering the html, the email just displays the html text..
Is there an easy way of rendering the html? Thanks for the help!
I’m trying to render html in an email and even after searching the web,
Share
You have to properly encode your email to indicate that it is HTML by setting the Content-type to text/html.
See http://en.wikipedia.org/wiki/MIME for solid background information.
Depending on your platform, there’s almost certainly a toolset to simplify this. For example, on Microsoft ASP.Net, I use MvcMailer. If you specify your platform, I’ll make a concrete recommendation.
For PHP, here’s a great article on sending nicely formatted HTML email