Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schvoy/mail-template-bundle
Mail template bundle helps to build and send emails from different source (Twig or Database).
https://github.com/schvoy/mail-template-bundle
bundle mailer php symfony symfony-bundle symfony-mailer
Last synced: 5 days ago
JSON representation
Mail template bundle helps to build and send emails from different source (Twig or Database).
- Host: GitHub
- URL: https://github.com/schvoy/mail-template-bundle
- Owner: schvoy
- License: mit
- Created: 2021-12-15T00:04:09.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-07T08:23:33.000Z (5 months ago)
- Last Synced: 2024-12-18T03:36:34.632Z (15 days ago)
- Topics: bundle, mailer, php, symfony, symfony-bundle, symfony-mailer
- Language: PHP
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Mail template bundle
Mail template bundle helps to build and send emails from different source (Twig or Database).
## Installation
### Install via composer
```bash
composer require schvoy/mail-template-bundle
```### Register templates in twig configuration
```yaml
twig:
...
paths:
'%kernel.project_dir%/vendor/schvoy/mail-template-bundle/src/Resources/views': MailTemplateBundle
```## Define the required environment variables
* MAILER_SENDER_ADDRESS
* MAILER_SENDER_NAME
* MAILER_SIGNATORY## Usage
### Twig based emails
Basically if you are using Twig based emails, the bundle will use a default email template (`email_base_template`).
You need to define only `subject` and `body` parameters.
These can be texts or translation keys.If you use custom email template (override: `email_base_template` configuration) you can add more parameters to your MailType(s),
and these parameters will be reachable in your template.```twig
{{ __mailType.subject }}
{{ __mailType.body }}
{{ __mailType.customParameter }}
```> Parameters have to have public access or a public method to reach it
#### Creating new twig based mail type
```php
getMailType(TestMailType::class);$mailSender->send(
$testMail,
[
new Recipient('[email protected]', 'Test user'),
new Recipient('[email protected]'),
],
[
'parameters' => [
'%test%' => 'Test parameter',
],
]
);
```### Default email (template) parameters
```php
[
'__greeting' => true,
'__signature' => true,
'__userName' => $recipient->getName() ?? false,
'__mailType' => $mailType,
'__translationDomain' => $this->parameterBag->get(
sprintf('%s.%s', MailTemplateBundleExtension::ALIAS, 'translation_domain')
),
'__locale' => 'en',
'parameters' => [
'%userName%' => $recipient->getName(),
'%signatory%' => $this->parameterBag->get('mailer_signatory'),
],
]
```## Configuration reference
```
mailer_template_bundle:
translation_domain:
email_base_template:
email_base_css_template:
```## Not supported yet - TODO
* Database based mail types
* CC and BCC
* Attachment for mails