Good all the time of day.

The task was to write a utility for sending letters. There is no problem with the utility itself. There are problems with the layout of letters.

As you know, HTML layout of the letter itself is not a trivial thing, since it differs from the usual HTML layout of ordinary pages in terms of supporting various features.

The biggest problem is the lack of support for <style> in <head> for GMail (more here ). Those. as you understand, you cannot jot down common CSS styles for elements by selectors. These styles should be assigned to each element through the style="" attribute.

Very cool, this problem is solved at mailchimp.com . They have a built-in parser that parses the <style> and hangs styles to the corresponding elements. Those. Here is a letter:

 ... <style> a { color: green; } a.someLink { color: red; } </style> ... <body> ... <a class="someLink">first</a> <a class="anotherClass">second</a> <a>third</a> ... 

Converted to the form:

 ... <style> a { color: green; } a.someLink { color: red; } </style> ... <body> ... <a class="someLink" style="color: red;">first</a> <a class="anotherClass" style="color: green;">second</a> <a style="color: green;">third</a> ... 

This is very cool, and this is what we need to achieve. The bottom line is that the letter has a stylized template and it is assumed that its content letters are edited using a WYSIWYG editor. Those. The content of the letter is obtained in the form of HTML, but due to the lack of support for the <style> , the content is not formatted according to the style of the template itself.

The most ideal option is to find some kind of tool with which to do the same thing that mailchimp does. Those. some kind of DOM and CSS parser that gives the DOM with hung styles. Maybe someone knows about something similar?

PS: ideally, of course, in PHP :)

  • Python is no good at all? - gecube
  • @gecube why? It fits. PHP would be perfect, since the project is written on it, but I can connect anything. - IntellectSys

1 answer 1

Use the tools that the Zurb Foundation offers.
There is also a template engine that allows you to write less code (for example, a column system that automatically turns into a mince from tables from one tag), and an inliner (what you are asking about).

They are delivered as npm-packages, but nobody prevents you from installing them and calling them from your php code. On what the tools themselves are written, in theory, you should not care.

  • You are my savior, thank you. Yes, I, in principle, no matter what language the instrument is written in. I can connect anything :) - IntellectSys