creonit / mailing-bundle
Installs: 7 060
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=7.2.5
- creonit/admin-bundle: >=1.0.2
- creonit/propel-schema-converter-bundle: ^0.2.5
- propel/propel: ^2.0
- propel/propel-bundle: ^5.0
- symfony/event-dispatcher: ^4.4|^5.0
- symfony/framework-bundle: ^4.4|^5.0
- symfony/mailer: ^4.4|^5.0
- symfony/yaml: ^4.4|^5.0
Requires (Dev)
- symfony/profiler-pack: ^1.0
This package is auto-updated.
Last update: 2024-10-22 20:29:52 UTC
README
# config/packages/creonit_mailing.yaml creonit_mailing: from: 'noreply@creonit.ru' base_template: 'mail/base.html.twig' templates_path: '%kernel.project_dir%/config/mailing_templates' globals: parameter: 'value'
# config/mailing_templates/template.yaml example: title: 'Example Template' from: email: 'noreply@creonit.ru' name: 'Creonit' subject: 'Welcome' template: '<div>{{ message }}</div>'
custom template loader
use Creonit\MailingBundle\Templating\Loader\AbstractTemplateLoader; use Creonit\MailingBundle\Templating\MailingTemplate; use Creonit\MailingBundle\Templating\TemplateCollection; class MyTemplateLoader extends AbstractTemplateLoader { public function load(TemplateCollection $templateCollection) { $template = new MailingTemplate('my_template'); $template ->setTitle('Example custom loader') ->setSubject('Example custom loader') ->setTemplate('<p>Custom loader</p>'); $templateCollection->add($template); } }
custom message builder
use Creonit\MailingBundle\Message\MailingMessage; use Creonit\MailingBundle\Message\MessageBuilderInterface; use Creonit\MailingBundle\Templating\MailingTemplate; class MyMessageBuilder implements MessageBuilderInterface { public function build(MailingTemplate $template, array $context): MailingMessage { $message = new MailingMessage(); $message->cc('major@gmail.com'); return $message; } public function supports(MailingTemplate $template, array $context): bool { return $template->getKey() === 'my_template'; } }
send message
use Creonit\MailingBundle\Mailing; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Mailer\MailerInterface; class MailingController extends AbstractController { public function sendEmail(Mailing $mailing, MailerInterface $mailer) { $email = 'example@exmple.com'; $template = 'my_template'; $message = $mailing->buildMessage($template, ['message' => 'Hello']); $message->to($email); $mailer->send($message); } }