HTML mail goes out through _class('email') (yf_email): _send_email_safe() and _send_to_default_admin() turn the HTML into a plain-text part and inline its CSS before the mail driver sends it. API: API reference / yf_email.

CSS inlining

Many mail clients ignore <style> elements, so the rules of the mail's <style> elements are written into the style attribute of each element they match. Two inliners exist; the property CSS_INLINER picks one:

$PROJECT_CONF['email']['CSS_INLINER'] = 'yf';      // the built-in inliner
$PROJECT_CONF['email']['CSS_INLINER'] = 'legacy';  // default until 4.0: the css-to-inline-styles 1.5 fork
_class('email')->_css_to_inline_styles($html, ['css' => 'p { margin: 0 }']);  // extra CSS: yf inliner only

Tools / Settings has it on the Mail tab. In 4.0 the default becomes 'yf' and the fork goes.

legacyyf
Codecss-to-inline-styles 1.5.4 (2014) and a fork of Symfony CssSelector, loaded on every HTML mailyf_email_css_inliner, DOM and libxml only
Selectorswhat CssSelector translatesthe subset below; other rules are kept, not dropped
@media, :hover, other rules not inlinedremoved with every <style> elementkept in one <style> element: in the head, or first in a mail that is a fragment
<style media="print">inlined as screen rules, then removedleft as it is
The universal selector *also writes a style on the head elementsbody side only (and <html>)
Order of the properties in a rulesorted by nameas written (a shorthand after a longhand overrides it)
Text encodingread from a <meta charset> (a full document without one is read as Latin-1)always UTF-8; invalid bytes are replaced
@import, @charsetdropped, and the rule after @import with itdropped; nothing is fetched

Selectors of the yf inliner

  • type td, universal *, class .button, id #footer, attribute [href] and [align=center] (value bare or quoted, exact match);
  • compounds of these (td.muted, a.button[href]);
  • :first-child, :last-child and :nth-child() with odd, even, a number or an an+b form (2n+1, 3n, -n+3, n+5);
  • descendant .header td, child .content > p, next-sibling tr + tr td and subsequent-sibling h1 ~ p combinators, lists h1, h2.

Anything else (:hover, :nth-last-child(), :only-child, :nth-child(2 of .a), :not(), ::before, [href^=...], escapes) is not inlined: the rule stays in the <style> element for the clients that read it. In a list, the supported selectors are inlined and only the others are kept.

Which declaration wins: the higher specificity (ids, then classes / attributes / pseudo-classes, then types; combinators count nothing), then the later rule; an !important declaration is only replaced by another !important one. The element's own style attribute wins over every rule, !important ones too, as with the legacy inliner. Several values of one property in one rule (fallbacks such as background: #fff; background: rgba(0,0,0,.5)) are all kept.

The mail HTML may come from users or other systems: it is parsed with network access and external entities off (no XXE), and the kept CSS cannot close its <style> element. <script> elements are removed in both modes.