PHP code example of ttskch / twigged-swiftmessage-builder

1. Go to this page and download the library: Download ttskch/twigged-swiftmessage-builder 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/ */

    

ttskch / twigged-swiftmessage-builder example snippets


// in your application.

$builder = new \Ttskch\TwiggedSwiftMessageBuilder\TwiggedSwiftMessageBuilder($tiwg);  // $twig is an instance of \Twig_Environment class.

$message = $builder->buildMessage('email.txt.twig');
$message->setTo('[email protected]');

$mailer->send($message);    // $mailer is an instance of \Swift_Mailer class.

// in your application.

$builder = new \Ttskch\TwiggedSwiftMessageBuilder\TwiggedSwiftMessageBuilder($tiwg);

$message = $builder->buildMessage('email.txt.twig', array(
    'site_title' => 'FooBar Service',
));
$message->setTo('[email protected]');

$mailer->send($message);

// in your application.

$builder = new \Ttskch\TwiggedSwiftMessageBuilder\TwiggedSwiftMessageBuilder($tiwg);

$message = $builder->buildMessage('email.html.twig');

$style = file_get_contents('/path/to/style.css');

$message = $builder->setInlineStyle($message, $style);

$mailer->send($message);

// in your application.

$builder = new \Ttskch\TwiggedSwiftMessageBuilder\TwiggedSwiftMessageBuilder($tiwg);

$message = $builder->buildMessage('email.html.twig', array(
    'image_path' => '/path/to/image/file',
));

// you can get renderable html with base64 encoded images. (In case you want to print preview.)
$renderableHtml = $builder->renderBody($message);

// you must finalize embedding before send message.
$message = $builder->finalizeEmbedding($message);

$mailer->send($message);