11

I was over at MailChimp's css inliner http://www.mailchimp.com/labs/inlinecss.php and I was wondering if there are any classes out there that can do this, I'd love to have it in my email code instead of going all the way over to MailChimp.

Basically I'm looking for the code, behind the page or something very similar.

Cheers.

2
  • So do you want a custom HTML parsing engine or do you want that page or what? Can you give a little more detail WHAT it is you want the supposed PHP class to do? Commented Oct 21, 2010 at 18:35
  • Sorry about that, thought the post was pretty clear. The other dude picked it up OK. Shame it's ruby. I edited the post to be a little more specific. Commented Oct 21, 2010 at 19:43

7 Answers 7

9

How's this?

https://www.myintervals.com/emogrifier.php

"... Emogrifier automagically transmogrifies your HTML by parsing your CSS and inserting your CSS definitions into tags within your HTML based on your CSS selectors. You can either use the form below to paste your HTML or CSS, or if you're more technically inclined, you can download the PHP source code and use it in your own applications. "

Sign up to request clarification or add additional context in comments.

3 Comments

Looks like it does not support css styles applied to tags eg h1 {color: red}, only classes.
Actually demo on web site does not however downloadable code does. There's another issue though that it does not strip class attribute after creating inline style attribute.
@alexeit: Actually I've since learnt that you can do this via the MailChimp API (apidocs.mailchimp.com/rtfm/inlinecss.func.php) after signing up for a free account. Plus it's able to strip the original CSS.
8

I was looking for the same thing tonight and I found this library https://github.com/christiaan/InlineStyle ,which does what I think you want.

It even understand selectors like ul > li and such.

Comments

3

You can try Premailer. The source is available on Github. (Just noticed your tag is PHP and Premailer is Ruby, so this might not count as a real answer for you...)

Comments

2

Emogrifier did not work for me, so I have developed this: https://github.com/djfm/cssin. I've tried several other libs and none worked on my HTML files, my lib is pretty OK I think.

Comments

2

Pure PHP solution: https://github.com/tijsverkoyen/CssToInlineStyles (used by ).

tijsverkoyen/css-to-inline-styles if using .

Comments

1

The link in the OP appears to be gone, but MailChimp offers a style-to-inline convertor for free with no signup here:

http://beaker.mailchimp.com/inline-css

Still have to go "all thet way over to Mailchimp", though!

Comments

1

I was looking for the same thing (PHP based, downloadable, open source), but couldn't find it, so I created the following proxy/wrapper for the open source ruby library: https://github.com/onassar/PHP-Premailer

Hope it's helpful.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.