Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/975l/emailbundle
Bundle to manage sending emails and store in a database
https://github.com/975l/emailbundle
swiftmailer symfony symfony-bundle
Last synced: about 1 month ago
JSON representation
Bundle to manage sending emails and store in a database
- Host: GitHub
- URL: https://github.com/975l/emailbundle
- Owner: 975L
- License: mit
- Created: 2017-06-05T10:04:26.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-09-15T16:22:29.000Z (2 months ago)
- Last Synced: 2024-10-01T15:27:58.373Z (about 2 months ago)
- Topics: swiftmailer, symfony, symfony-bundle
- Language: PHP
- Homepage: https://975l.com/en/pages/email-bundle
- Size: 232 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# EmailBundle
EmailBundle does the following:
- Stores email in a database as an option,
- Sends email using [Symfony Mailer](https://github.com/symfony/mailer),
- Allows user with good ROLE to see emails sent,
- Defines a template for emails that should be overriden to integrate fully with website,
- Allows to attach one or multiple files.[EmailBundle dedicated web page](https://975l.com/en/pages/email-bundle).
[EmailBundle API documentation](https://975l.com/apidoc/c975L/EmailBundle.html).
## Bundle installation
### Step 1: Download the Bundle
Use [Composer](https://getcomposer.org) to install the library
```bash
composer require c975l/email-bundle
```### Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles in the `app/AppKernel.php` file of your project:
```php
{{ 'label.description'|trans }} : {{ object.description }}
{# You can include files #}
{% include 'YOUR_FILE_PATH' %}
{% endblock %}
```Then in your Controller, add this code to create, insert in DB and send your email:
```php
renderView('emails/description.html.twig', array(
//Data needed for your template
));
$emailData = array(
'subject' => 'YOUR_SUBJECT',
'sentFrom' => $emailService->getParameter('c975LEmail.sentFrom'),
'sentTo' => '[email protected]',
'sentCc' => '[email protected]', //optional
'sentBcc' => '[email protected]', //optional
'replyTo' => '[email protected]', //optional
'body' => $body,
'attach' => array(
array($filePath, $filename, $contentType),
), //optional
'ip' => $request->getClientIp(), //optional
);//Sends email
$emailSent = $emailService->send($emailData, [saveDatabase ? true|false(default)]);//You can test if email has been sent
if ($emailSent) {
//Do what you need...
} else {
//Do what you need...
}// ...
}
}
```### Email messages templates
If you wish to override/disable a block defined in the `fullLayout.html.twig` template, create your `templates/bundles/c975LEmailBundle/emails/layout.html.twig` and use the following code:
```twig
{% extends "@c975LEmail/emails/fullLayout.html.twig" %}{# Overide a block #}
{% block noSpam %}
{# You can also use {{ parent() }} #}
{# YOUR_OWN_TEXT #}
{% endblock %}{# Disable a block #}
{% block logo %}
{% endblock %}
```Have a look at `templates/emails/fullLayout.html.twig`, to see all available blocks.
### Footer template
You should override the template `templates/emails/footer.html.twig` in your `templates/bundles/c975LEmailBundle/emails/footer.html.twig` and indicate there all the data you need to display at the bottom of sent email.
### Use of dashboard and display messages sent
You can see the emails sent via the dashboard.
For this, simply, create the following structure `templates/bundles/c975LEmailBundle/` in your app and then duplicate the file `layout.html.twig` in it, to override the existing Bundle files, then apply your needed changes.
In `layout.html.twig`, it will mainly consist to extend your layout and define specific variables, i.e. :
```twig
{% extends 'layout.html.twig' %}
{# or extends 'emails/layout.html.twig' #}{# Defines specific variables #}
{% set title = 'Email (' ~ title ~ ')' %}{% block content %}
{% block email_content %}
{% endblock %}
{% endblock %}
```If this project **help you to reduce time to develop**, you can sponsor me via the "Sponsor" button at the top :)