2017 © Pedro Peláez
 

library twigmailer

image

rauwebieten/twigmailer

  • Monday, June 12, 2017
  • by rauwebieten
  • Repository
  • 1 Watchers
  • 2 Stars
  • 20 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 5 % Grown

The README.md

TwigMailer

Send mails with PHPMailer and a Twig template., (*1)

  • Uses a PHPMailer instance for sending the mail
  • Uses a Twig Environment to render templates
  • Creates a text version from the HTML version
  • If linked CSS files are found in the HTML, they are loaded and converted to inline styles
  • Sets the subject from the HTML title tag

Installation

Install with composer/packagist, (*2)

composer require rauwebieten/twigmailer, (*3)

Basic usage

Make sure you have a configured PHPMailer instance. Check the PHPMailer documentation for details., (*4)

$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/templates');  
$twig = new \Twig\Environment($loader);

Make sure you have a configured Twig Environment instance. Check the Twig documentation for details., (*5)

$phpMailer = new \PHPMailer();
$phpMailer->Mailer = 'mail';
$phpMailer->setFrom('me@example.com', 'Me');

Create a TwigMailer instance, (*6)

$mailer = new \RauweBieten\TwigMailer\TwigMailer($phpMailer, $twig);

Create content from the template, (*7)

$mailer->create('some-template.html.twig', [
    'some-variable' => 'Some value'
]);

And send the mail, (*8)

$mailer->getPhpMailer()->addAddress('someone@example.com', 'Someone');
$mailer->send();

The Versions