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.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
CafeHey
  • 5,699
  • 19
  • 82
  • 145
  • 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? – jcolebrand Oct 21 '10 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. – CafeHey Oct 21 '10 at 19:43

7 Answers7

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. "

Mesa
  • 289
  • 2
  • 10
Tom
  • 30,090
  • 27
  • 90
  • 124
  • Looks like it does not support css styles applied to tags eg h1 {color: red}, only classes. – Alexei Tenitski Jun 17 '11 at 06:33
  • 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. – Alexei Tenitski Jun 19 '11 at 23:31
  • 2
    @alexeit: Actually I've since learnt that you can do this via the MailChimp API (http://apidocs.mailchimp.com/rtfm/inlinecss.func.php) after signing up for a free account. Plus it's able to strip the original CSS. – Tom Jun 19 '11 at 23:51
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.

John Conde
  • 217,595
  • 99
  • 455
  • 496
ArnAud
  • 81
  • 1
  • 1
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...)

Andrew Vit
  • 18,961
  • 6
  • 77
  • 84
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.

djfm
  • 2,317
  • 1
  • 18
  • 34
2

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

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

Leith
  • 3,139
  • 1
  • 27
  • 38
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!

George Langley
  • 453
  • 4
  • 12
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.

onassar
  • 3,313
  • 7
  • 36
  • 58