PHPackages                             phps-cans/mail.swift.renderer-twig - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. phps-cans/mail.swift.renderer-twig

ActiveLibrary[Templating &amp; Views](/categories/templating)

phps-cans/mail.swift.renderer-twig
==================================

This package contains a implementation of the SwiftMailRenderer interface which use twig to render the mail message.

v5.0.0(9y ago)014MITPHPPHP &gt;=7.0.0

Since Jan 19Pushed 9y ago2 watchersCompare

[ Source](https://github.com/phps-cans/mail.swift.renderer-twig)[ Packagist](https://packagist.org/packages/phps-cans/mail.swift.renderer-twig)[ Docs](https://github.com/phps-cans/mail.swift.renderer-twig)[ RSS](/packages/phps-cans-mailswiftrenderer-twig/feed)WikiDiscussions 5.0 Synced 4w ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

[![Build Status](https://camo.githubusercontent.com/5b9bce87eb62e122a660ff1e1a093f9a0ed805a0973474e44562f1ca4dd1b847/68747470733a2f2f7472617669732d63692e6f72672f746865636f64696e676d616368696e652f73776966742d747769672d6d61696c2d74656d706c6174652e7376673f6272616e63683d352e30)](https://travis-ci.org/thecodingmachine/swift-twig-mail-template)[![Coverage Status](https://camo.githubusercontent.com/0c36c25d03e87b8644a30e545f0312b5c6cbccad8da49d34937ac6abda957d80/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746865636f64696e676d616368696e652f73776966742d747769672d6d61696c2d74656d706c6174652f62616467652e7376673f6272616e63683d352e3026736572766963653d676974687562)](https://coveralls.io/github/thecodingmachine/swift-twig-mail-template?branch=5.0)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/90407567af0520ad97851a255b10c577f0bb990c15f35b8e5140c831434bef69/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f73776966742d747769672d6d61696c2d74656d706c6174652f6261646765732f7175616c6974792d73636f72652e706e673f623d352e30)](https://scrutinizer-ci.com/g/thecodingmachine/swift-twig-mail-template?b=5.0)[![Code Coverage](https://camo.githubusercontent.com/2a27733b9f1fdecda1e2f64d5a2ca7fe660e9ef4491b9ce1e821c884c0b1b4de/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f73776966742d747769672d6d61696c2d74656d706c6174652f6261646765732f636f7665726167652e706e673f6272616e63683d352e30)](https://scrutinizer-ci.com/g/thecodingmachine/swift-twig-mail-template?b=5.0)[![Open Source Love](https://camo.githubusercontent.com/f51de32d275906916ae11f73fb488c3d6c2710e9c36da34ecef00358129bce52/68747470733a2f2f6261646765732e66726170736f66742e636f6d2f6f732f76312f6f70656e2d736f757263652e7376673f763d313032)](https://github.com/ellerbrock/open-source-badge/)[![Open Source Love](https://camo.githubusercontent.com/2d4eac62d5f5830a5309100b88e0ecccb171aee1fbcd794149f4a580b0010c56/68747470733a2f2f6261646765732e66726170736f66742e636f6d2f6f732f6d69742f6d69742e7376673f763d313032)](https://github.com/ellerbrock/open-source-badge/)

Swift Twig Mail Generator
=========================

[](#swift-twig-mail-generator)

This package takes a Twig template and generates a Switf mail from this template.

Installation
------------

[](#installation)

```
composer require thecodingmachine/swift-twig-mail-template

```

Once installed, you can start creating an instance of the `SwiftTwigMailTemplate` class.

The `SwiftTwigMailTemplate` represents a mail template that can generate Swift mails.

Example
-------

[](#example)

Because we consider that an example is better than everything else...

Start by creating your mail template. Your template should have two blocks:

```
{% block subject %}
    Your suject
{% endblock %}

{% block body_html %}
    Body with HTML.
{% endblock %}
```

If you want you can add another block containing your text body. This block is optional since we can get your the text body directly from the html one.

```
{% block body_text %}
    Body without HTML.
{% endblock %}
```

Now, let's create a `SwiftTwigMailTemplate` instance. This object will generate a `SwiftMail` from the twig template.

```
// We assume that $twigEnvironment is a valid TwigEnvironment instance
$twigSwiftMailTemplate =  new SwiftTwigMailTemplate($twigEnvironment, 'path/to/template.twig');

// The renderMail method generates a Swift mail object.
$swiftMail = $twigSwiftMailTemplate->renderMail(['paramKey' => paramValue]);

// We fill the swift mail with additional information
$swiftMail->setFrom('sender@example.com');
$swiftMail->setTo('recipient@example.com');

// We assume that $mailer is a valid Swift_Mailer instance
$mailer->send($swiftMail);
```

### Going further

[](#going-further)

The `SwiftTwigMailTemplate` class has been designed with dependency injection in mind. Instances can be easily put in your container for easy reuse. Furthermore, the `SwiftTwigMailTemplate` class shares a lot with the `Swift_Mail` class. You can:

- setting the from address
- setting the from name
- setting the to address
- setting the to name
- setting the Bcc address
- setting the Bcc name
- setting the Cc address
- setting the Cc name
- setting the ReplyTo address
- setting the ReplyTo name
- setting the max line size
- setting the priority
- setting the read receip to
- setting the return path

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3449d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/988fb049e7b031fc14b8ce38b8f5bc3e40dbd6bfb3b5bc7f7061b68c41ba39f1?d=identicon)[xhuberty](/maintainers/xhuberty)

---

Top Contributors

[![xhuberty](https://avatars.githubusercontent.com/u/8350192?v=4)](https://github.com/xhuberty "xhuberty (2 commits)")

---

Tags

twigmailswift

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phps-cans-mailswiftrenderer-twig/health.svg)

```
[![Health](https://phpackages.com/badges/phps-cans-mailswiftrenderer-twig/health.svg)](https://phpackages.com/packages/phps-cans-mailswiftrenderer-twig)
```

###  Alternatives

[timber/timber

Create WordPress themes with beautiful OOP code and the Twig Template Engine

5.7k3.6M127](/packages/timber-timber)[twig/intl-extra

A Twig extension for Intl

36567.2M322](/packages/twig-intl-extra)[symfony/ux-twig-component

Twig components for Symfony

22017.2M313](/packages/symfony-ux-twig-component)[symfony/ux-live-component

Live components for Symfony

1636.5M116](/packages/symfony-ux-live-component)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

22919.7M82](/packages/twig-cssinliner-extra)[twig/inky-extra

A Twig extension for the inky email templating engine

16613.2M71](/packages/twig-inky-extra)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
