dev-master
9999999-devProvides functional for send emails using email templates and less generating functionality for end emails
MIT
The Requires
by sam0delkin
by Evgeniy Davydov
mail swiftmailer less templates
Provides functional for send emails using email templates and less generating functionality for end emails
Provides functional for send emails using email templates and less generating functionality for end emails, (*1)
Pretty simple with Composer, run:, (*2)
composer require ite/mail-bundle
You can configure default parameters for email senders and using styles for email templates, (*4)
ite_mail: bcc_email: %bcc_email% from_email: %support_email% support_email: %support_email% noreply_email: %noreply_email% template_folder: AcmeCoreBundle:Email/Template #folder with all email templates styles: ['@AcmeCoreBundle/Resources/public/less/email/style.less', '@AcmeCoreBundle/Resources/public/less/email/style2.less'] #additional styles for email templates will be generated to inline styles in end email translation_domain: email_subjects #provide translations for end email subjects
// app/AppKernel.php public function registerBundles() { return array( // ... new ITE\MailBundle\ITEMailBundle(), // ... ); }
Create tokens based on context name, (*5)
// src/Acme/CoreBundle/Extension/Mail namespace Acme\CoreBundle\Extension\Mail; use ITE\MailBundle\Extension\BaseExtension; use ITE\MailBundle\Extension\TokenExtensionInterface; use ITE\MailBundle\Token\Context; use ITE\MailBundle\Token\Token; use Symfony\Component\DependencyInjection\ContainerInterface; class MainExtension extends BaseExtension implements TokenExtensionInterface { private $twig; private $container; /** * @param ContainerInterface $container * @internal param $twig */ function __construct(ContainerInterface $container) { $this->container = $container; $this->twig = $container->get('twig'); } /** * Retrieve token list depend on token context * * @param Context $context * * @return Token[] */ public function getTokens(Context $context) { $this->setContext($context); $data = $context->getData(); switch ($context->getName()) { case 'test_context_name': return [ new Token('test_token', $data['someData'], 'Test Token'), ]; break; } return []; } public function setContext(Context $context) { if ($context->getData()) { return null; } } /** * Retrieve global token list, not depended on context * * @return Token[] */ public function getGlobals() { return []; } }
Add mail extension to services.yml, (*6)
services: admin.mail.token.main_extension: class: Acme\CoreBundle\Extension\Mail\MainExtension arguments: [@service_container] tags: - {name: ite.mail.extension}
Create the template test_template.html.twig in AcmeCoreBundle:Email/Template folder, (*7)
Hi User, [test_token] {#This is the token name from Acme\CoreBundle\Extension\Mail\MainExtension#}
You can send email using template test_template.html.twig:, (*8)
// Acme\MainBundle\Controller\ArticleController.php public function sendAction() { $data = ['someData' => 123]; $this ->get('ite.mail.manager') ->mail('test_template', 'some_email@mail.com', 'Some subject', [ 'token_context' => new Context($data, 'test_context_name') ]); return []; }
Provides functional for send emails using email templates and less generating functionality for end emails
MIT
mail swiftmailer less templates