An open API service indexing awesome lists of open source software.

https://github.com/fullpipe/email-template-bundle


https://github.com/fullpipe/email-template-bundle

Last synced: 10 months ago
JSON representation

Awesome Lists containing this project

README

          

# About EmailTemplateBundle
Keep email templates in repo and in order.
## Installation
First you need to add `fullpipe/email-template-bundle` to `composer.json`:
```json
{
"require": {
"fullpipe/email-template-bundle": "dev-master"
}
}
```
You also have to add `EmailTemplateBundle` to your `AppKernel.php`:
```php
// app/AppKernel.php
class AppKernel extends Kernel
{
//...
public function registerBundles()
{
$bundles = array(
//...
new Fullpipe\ImageBundle\FullpipeImageBundle()
);

return $bundles;
}
//...
}
```
## Configuration
```yaml
fullpipe_email_template:
# default from email
from: # or simply from: noreply@example.com
email: noreply@example.com
name: noreply

# default no reply email
reply_to: # or simply reply_to: reply@example.com
email: reply@example.com
name: We are waiting for your reply

# default utm-marks for links in emails (optional)
utm:
utm_source: source_test
utm_medium: medium_test
utm_campaign: campaign_test

# default host for which utm-marks will be applied
host: %router.request_context.scheme%://%router.request_context.host%

# Your templates
# requires at least one template
templates:
default: # template name
# template uri
template: "FullpipeEmailTemplateBundle:Template:default.html.twig"

# custom utm-marks (optional)
utm:
utm_source: source_default
utm_medium: medium_default
utm_campaign: campaign_default

# custorm host (optional)
host: http://example.com

# generate text version automatically, true by default
generate_text_version: true
#...
```
## Usage
For example we need to send confirmation email, after user registration.
First, we need to add template config:
```yaml
fullpipe_email_template:
#...
templates:
reg_confirmation:
template: "AcmeWebBundle:EmailTemplates:reg_confirmation.html.twig"
utm:
utm_source: reg_confirmation
utm_medium: email
```
Second, we need to create `AcmeWebBundle:EmailTemplates:reg_confirmation.html.twig`:
```twig
{% block subject %}Good to you, {{ username }}{% endblock %}
{% block body_html %}






...



Hello, {{ username }}


Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magnam deserunt magni libero quas aperiam, labore harum, eos expedita, dolores autem illum? Fugiat, molestias, minus. Libero impedit fugit inventore, aliquid perspiciatis.




{% endblock %}
```
And we could send our email:
```php
$this->get('fullpipe_email_template.mailer')
->prepareMessage('reg_confirmation', array('username' => 'USERNAME!'))
->setTo('username@example.com', 'USERNAME!')
->send();
```
## Profits
- if in twig template block `{% block body_text %}...{% endblock %}` is missing and option `generate_text_version` is `true` then text version will be generated by [html2text](https://github.com/mtibben/html2text)
- html version is processed by [CssToInlineStyles](https://github.com/tijsverkoyen/CssToInlineStyles)