Reputation: 91
i want to send email(type = HTML)using codeigniter and am doing fine,But css styles are not applying to the mail.
<html>
<head>
<style type="text/css">
body
{
background-color:#b0c4de;
}
</style>
</head>
<body>
<h1>My CSS web page!</h1>
<p>Hello world! This is a W3Schools.com example.</p>
</body>
</html>
Expected output (with a background colour of #b0c4de on the entire email):
Hello world! This is a W3Schools.com example.
There is no background-color though. What is solution for this?
Upvotes: 0
Views: 2468
Reputation: 3404
It looks like Ben Swinburne with his answer solved your issue, however here is some more information I found useful.
1) Premailer.dialect.ca API will convert all CSS in the <style>
tags into inline CSS.
It works great. It actually uses the same engine as campaignmonitor.com.
http://premailer.dialect.ca/api
It scares me that the API is in beta and there is no paid option. However, they say if they discontinue the API they will give 30 days notice and release the source code. I still question the reliability of their server uptime. For commercial applications, I use the API but if the API is unavailable I just go without the service since its not critical to my system. If anyone knows of a better service (cheap), please let me know.
2) Litmus.com
It looks like Litmus API will allow you to do some crazy cool things, if you can pay. I am looking at using their Reseller account for a commercial website right now.
3) Check out MailChimps Email Blueprints.
They have been working on email templates longer than most and these are a great way to get started with emails that work in most clients. https://github.com/mailchimp/Email-Blueprints
4) Also, make sure you have this header set
This is just a bonus tip, I just always forget to include that header then spend hours wondering why my HTML is not processed.
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Check out services like:
I thought I didn't need them because PHP lets me send emails, but once you use their service you won't go back. They provide such critical metrics for any company. I didn't know that 6% of my emails are bouncing and 1% are marking it as spam. I use SendGrid right now. Postmark & Mandrill (MailChimp created) look like great solutions for bootstrap companies. Cheap prices and great service.
Upvotes: 0
Reputation: 26477
CSS support is limited in email clients. Although CSS background colour is supported in most browsers, your style declaration may not be. For example if you're checking using Gmail you won't see it as your style declaration in the head tag isn't supported.
You should consider reading the following page.
http://www.campaignmonitor.com/css/
You can use tables and the bgcolor=""
attribute relatively safely in HTML emails or you can style elements individually using the style="bgcolor='';" attribute
This should do the trick
<table width="100%" style="background-color:#b0c4de;" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<h1>My CSS web page!</h1>
<p>Hello world! This is a W3Schools.com example.</p>
</td>
</tr>
</table>
Upvotes: 1