PHP code example of trt / swift-css-inliner-bundle

1. Go to this page and download the library: Download trt/swift-css-inliner-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

trt / swift-css-inliner-bundle example snippets


$bundles = array(
    [...]
    new \Trt\SwiftCssInlinerBundle\TrtSwiftCssInlinerBundle(),
);

/**
 * @Route("/hello/{name}", name="_demo_hello")
 */
public function helloAction($name)
{
    $message = \Swift_Message::newInstance()
        ->setSubject('Hello Email')
        ->setFrom('[email protected]')
        ->setTo('[email protected]')
        ->setContentType('text/html')
        ->setBody("<style>.text{ color: red; }</style><p class='text'> $name </p>")
    ;
    $message->getHeaders()->addTextHeader(
        CssInlinerPlugin::CSS_HEADER_KEY_AUTODETECT
    );

    $this->get('mailer')->send($message);
}

$message = \Swift_Message::newInstance()
    ->setSubject('Hello Email')
    ->setFrom('[email protected]')
    ->setTo('[email protected]')
    ->setContentType('text/html')
    ->setBody('<style>.text{color:red;}</style>  <p class="text"> Hello </p>')
;

$message->getHeaders()->addTextHeader(
    CssInlinerPlugin::CSS_HEADER_KEY_AUTODETECT
);

$message->getHeaders()->addTextHeader(
    CssInlinerPlugin::CSS_HEADER_KEY, //The key that say to the plugin "Apply this CSS"
    ".text{ color: red; }"
);
 php
$this->get('mailer')->send($message);