rauwebieten / twigmailer
There is no license information available for the latest version (1.0.0-alpha) of this package.
1.0.0-alpha
2017-06-12 08:35 UTC
Requires
- php: >=5.4.0
- html2text/html2text: ^4.1
- pelago/emogrifier: ^1.2
- phpmailer/phpmailer: ^5.2
- twig/twig: ^1.0
- wa72/htmlpagedom: ^1.3
This package is auto-updated.
Last update: 2025-03-07 14:28:49 UTC
README
Send mails with PHPMailer and a Twig template.
- 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
composer require rauwebieten/twigmailer
Basic usage
Make sure you have a configured PHPMailer instance. Check the PHPMailer documentation for details.
$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.
$phpMailer = new \PHPMailer(); $phpMailer->Mailer = 'mail'; $phpMailer->setFrom('me@example.com', 'Me');
Create a TwigMailer instance
$mailer = new \RauweBieten\TwigMailer\TwigMailer($phpMailer, $twig);
Create content from the template
$mailer->create('some-template.html.twig', [ 'some-variable' => 'Some value' ]);
And send the mail
$mailer->getPhpMailer()->addAddress('someone@example.com', 'Someone'); $mailer->send();