disjfa / mail-bundle
Mail bundle for symfony, can also be use in glynn-admin-symfony
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Language:CSS
Type:symfony-bundle
Requires
- php: ^7.2.9
- ramsey/uuid: ^3
- symfony/form: ^4|^5
- symfony/mailer: ^4|^5
- symfony/mime: ^4|^5
- symfony/orm-pack: ^1.0
- symfony/translation: ^4|^5
- symfony/twig-bundle: ^4|^5
- symfony/validator: ^4|^5
- twig/cssinliner-extra: ^2.12
- twig/extra-bundle: ^2.12
- twig/inky-extra: ^2.12
This package is auto-updated.
Last update: 2024-10-22 06:48:23 UTC
README
Why is this bundle here
In every project i need to build a way to send emails. Now symfony has released the Mime Component and the Mailer Component. Lets see what we can do to make live easier for us people who send emails.
Instalation
composer require disjfa/mail-bundle
Setup the interface
Setup the routes in config/routes/disjfa_mail.yaml
. Here you can edit emails setup in your application.
disjfa_mail: resource: '@DisjfaMailBundle/Controller/' type: annotation prefix: '/admin'
Make you own template
Create a class that extends the MailInterface
. Implement the name, subject and content as you want. You can inject the Translator
to add simple translations or the twig Environment
to render out templates.
<?php namespace Disjfa\MailBundle\Mail; interface MailInterface { public function getName(); public function getSubject(); public function getContent(); }
In your templates there should be no twig variables. Escape those, like this: {{ '{{' }} email {{ '}}' }}
. All the variables used are parsed and collected. The original variables are the only ones that should be used.
If you made a class it will be autoload in the MailCollection
collection. And so editable if you have set up some routes for the interface.
Sending emails
Next up is sending emails. In your code just make a message or function that sets up the email.
use Disjfa\MailBundle\Mail\MailFactory; use Disjfa\MailBundle\Mail\MailService; function myFunction(MailFactory $mailFactory, MailService $mailService) { $mail = $mailFactory->findByName('name'); $mailService->send($mail, [ 'param1' => 'value', 'param2' => 'value', ], 'info@example.com'); }
And done! Mail sent. Now it is time to setup emails and make more in your application.
Extend the templates
You can manage the templates as is. But you probably want to integrate the files in your own system. Just create a file in your application in templates/bundles/DisjfaMailBundle/layout.html.twig
and add a body block.
<!doctype html> <html> <head> ... </head> <body> {% block body %} {% endblock %} </body> </html>
And you are good to go. Or you can just extend your own template. Just make sure you use a block named body
. You can also just extend the rest of the files as you wish. Just name them like we set up the files.
One thing missing
One thing missing is sending the emails. We do not have to set up the mailing bit of the application. You can do that yourself. Check the transports on how to set up your own mailer as you wish.
And that is about it.
Now you can make your own emails. Set them up. Create a method to send emails. And when you have set up your favorite mailer you can send them!
Help
This bundle is a nice way to extend your workflow. But it can be improved. If you have any ideas or solutions to do so don't be shy and tell us! We can only make stuff better in the end.
Enjoy!
Use the bundle. Check what the bundle does. Fork. Make your own. This is here just to make live easier for us all. Make something beautiful.