Download the PHP package pelago/emogrifier without Composer

On this page you can find all versions of the php package pelago/emogrifier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?
pelago/emogrifier
Rate from 1 - 5
Rated 1.00 based on 3 reviews

Informations about the package emogrifier

Emogrifier

Build Status Latest Stable Version Total Downloads License

n. e•mog•ri•fi•er [\ē-'mä-grƏ-,fī-Ər] - a utility for changing completely the nature or appearance of HTML email, esp. in a particularly fantastic or bizarre manner

Emogrifier converts CSS styles into inline style attributes in your HTML code. This ensures proper display on email and mobile device readers that lack stylesheet support.

This utility was developed as part of Intervals to deal with the problems posed by certain email clients (namely Outlook 2007 and GoogleMail) when it comes to the way they handle styling contained in HTML emails. As many web developers and designers already know, certain email clients are notorious for their lack of CSS support. While attempts are being made to develop common email standards, implementation is still a ways off.

The primary problem with uncooperative email clients is that most tend to only regard inline CSS, discarding all <style> elements and links to stylesheets in <link> elements. Emogrifier solves this problem by converting CSS styles into inline style attributes in your HTML code.

How it Works

Emogrifier automagically transmogrifies your HTML by parsing your CSS and inserting your CSS definitions into tags within your HTML based on your CSS selectors.

Installation

For installing emogrifier, either add pelago/emogrifier to the require section in your project's composer.json, or you can use composer as below:

See https://getcomposer.org/ for more information and documentation.

Usage

Inlining Css

The most basic way to use the CssInliner class is to create an instance with the original HTML, inline the external CSS, and then get back the resulting HTML:

If there is no external CSS file and all CSS is located within <style> elements in the HTML, you can omit the $css parameter:

If you would like to get back only the content of the <body> element instead of the complete HTML document, you can use the renderBodyContent method instead:

If you would like to modify the inlining process with any of the available options, you will need to call the corresponding methods before inlining the CSS. The code then would look like this:

There are also some other HTML-processing classes available (all of which are subclasses of AbstractHtmlProcessor) which you can use to further change the HTML after inlining the CSS. (For more details on the classes, please have a look at the sections below.) CssInliner and all HTML-processing classes can share the same DOMDocument instance to work on:

Normalizing and cleaning up HTML

The HtmlNormalizer class normalizes the given HTML in the following ways:

The class can be used like this:

Converting CSS styles to visual HTML attributes

The CssToAttributeConverter converts a few style attributes values to visual HTML attributes. This allows to get at least a bit of visual styling for email clients that do not support CSS well. For example, style="width: 100px" will be converted to width="100".

The class can be used like this:

You can also have the CssToAttributeConverter work on a DOMDocument:

Removing redundant content and attributes from the HTML

The HtmlPruner class can reduce the size of the HTML by removing elements with a display: none style declaration, and/or removing classes from class attributes that are not required.

It can be used like this:

The removeRedundantClasses method accepts a whitelist of names of classes that should be retained. If this is a post-processing step after inlining CSS, you can alternatively use removeRedundantClassesAfterCssInlined, passing it the CssInliner instance that has inlined the CSS (and having the HtmlPruner work on the DOMDocument). This will use information from the CssInliner to determine which classes are still required (namely, those used in uninlinable rules that have been copied to a <style> element):

The removeElementsWithDisplayNone method will not remove any elements which have the class -emogrifier-keep. So if, for example, there are elements which by default have display: none but are revealed by an @media rule, or which are intended as a preheader, you can add that class to those elements. The paragraph in this HTML snippet will not be removed even though it has display: none (which has presumably been applied by CssInliner::inlineCss() from a CSS rule .preheader { display: none; }):

The removeRedundantClassesAfterCssInlined (or removeRedundantClasses) method, if invoked after removeElementsWithDisplayNone, will remove the -emogrifier-keep class.

Options

There are several options that you can set on the CssInliner instance before calling the inlineCss method:

Migrating from the dropped Emogrifier class to the CssInliner class

Minimal example

Old code using Emogrifier:

New code using CssInliner:

NB: In this example, the old code removes elements with display: none; while the new code does not, as the default behaviors of the old and the new class differ in this regard.

More complex example

Old code using Emogrifier:

New code using CssInliner and family:

Supported CSS selectors

Emogrifier currently supports the following CSS selectors:

The following selectors are not implemented yet:

Rules involving the following selectors cannot be applied as inline styles. They will, however, be preserved and copied to a <style> element in the HTML:

Caveats

Steps to release a new version

  1. In the composer.json, update the branch-alias entry to point to the release after the upcoming release.
  2. In the CHANGELOG.md, create a new section with subheadings for changes after the upcoming release, set the version number for the upcoming release, and remove any empty sections.
  3. Create a pull request "Prepare release of version x.y.z" with those changes.
  4. Have the pull request reviewed and merged.
  5. Tag the new release.
  6. In the Releases tab, create a new release and copy the change log entries to the new release.
  7. Post about the new release on social media.

Maintainers


All versions of emogrifier with dependencies

PHP Build Version
Package Version
Requires php Version ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0
ext-dom Version *
ext-libxml Version *
sabberworm/php-css-parser Version ^8.4.0
symfony/css-selector Version ^4.4.23 || ^5.4.0 || ^6.0.0 || ^7.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pelago/emogrifier contains the following files

Loading the files please wait ....