PHPackages                             lemonade/email-generator - 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. lemonade/email-generator

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

lemonade/email-generator
========================

A PHP library for generating emails using Twig templates.

v0.2.0(1y ago)128MITPHPPHP &gt;=8.1 &lt;8.5

Since Dec 12Pushed 1y ago1 watchersCompare

[ Source](https://github.com/johnnyxlemonade/email-generator)[ Packagist](https://packagist.org/packages/lemonade/email-generator)[ RSS](/packages/lemonade-email-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (8)Used By (0)

Email Generator
===============

[](#email-generator)

[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)[![Build Status](https://camo.githubusercontent.com/4b4b77a1022ea0924d782c6ff9b4d87eae8cda3ede79c0aedc0aff2e8c38610c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6f686e6e79786c656d6f6e6164652f656d61696c2d67656e657261746f722f7068702d63692e796d6c3f6272616e63683d6d6173746572266c6162656c3d6275696c64)](https://camo.githubusercontent.com/4b4b77a1022ea0924d782c6ff9b4d87eae8cda3ede79c0aedc0aff2e8c38610c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6f686e6e79786c656d6f6e6164652f656d61696c2d67656e657261746f722f7068702d63692e796d6c3f6272616e63683d6d6173746572266c6162656c3d6275696c64)[![Packagist Version](https://camo.githubusercontent.com/87209ce87e10292eec8ce7f2ad27f2d4d46e57d7170a0c106319e721625f961f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c656d6f6e6164652f656d61696c2d67656e657261746f72)](https://camo.githubusercontent.com/87209ce87e10292eec8ce7f2ad27f2d4d46e57d7170a0c106319e721625f961f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c656d6f6e6164652f656d61696c2d67656e657261746f72)[![PHP Version](https://camo.githubusercontent.com/837b01c3a4445716199ec675e76fa287b1e54d673d3f44fe493e1c19f32bd85a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312532302d2d253230382e342d626c7565)](https://camo.githubusercontent.com/837b01c3a4445716199ec675e76fa287b1e54d673d3f44fe493e1c19f32bd85a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312532302d2d253230382e342d626c7565)

**Email Generator** is a PHP library for generating emails using the [Twig](https://twig.symfony.com/) templating system. This library allows easy template handling and provides a flexible way to integrate email generation into your project.

Basic Functionality
-------------------

[](#basic-functionality)

Email Generator provides an easy-to-use PHP library that leverages the power of the [Twig templating engine](https://twig.symfony.com/) to generate dynamic emails. The library is highly flexible and allows you to define custom templates for your emails, inject data into those templates, and render them as HTML or plain text emails. Here's how it works:

1. **Template Rendering**: The core feature is the ability to create email templates using Twig. These templates can contain placeholders (variables) that will be replaced by dynamic content at runtime.
2. **Data Injection**: You can pass data (such as user information, order details, etc.) into the templates. The library supports various data types, including arrays, objects, and scalars, allowing you to use your own application logic to populate the email content.
3. **Multi-Language Support**: The library supports translations out of the box, allowing you to generate emails in different languages by swapping dictionaries based on the user's preferred language.
4. **Flexible Email Content**: You can customize the content, including using inline CSS and HTML, embedding dynamic variables, or using more complex email layouts. You can also include graphical attachments using URLs provided via DTO.
5. **Seamless Integration**: It is designed to integrate seamlessly with any PHP project. The library can be used with frameworks like Laravel, Symfony, or as a standalone tool in any PHP application.
6. **Testable**: With the built-in unit tests, you can easily test the behavior of your templates and email generation logic. This ensures that emails are generated correctly under different conditions and with various data inputs.

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

[](#installation)

To install the library, use Composer:

```
composer require lemonade/email-generator
```

Usage Example: Lost Password Email
----------------------------------

[](#usage-example-lost-password-email)

Here’s how to use the DefaultBuilder to create a "lost password" email:

```
use Lemonade\EmailGenerator\DefaultBuilder;
use Lemonade\EmailGenerator\DefaultContainerBuilder;
use Lemonade\EmailGenerator\DTO\AddressData;

require __DIR__ . '/../vendor/autoload.php';

// Step 1: Create the container with pre-configured services
$container = DefaultContainerBuilder::create();

// Step 2: Create an address for the footer
$addressService = $container->getAddressService(); // Fetch the AddressService from the container
$footerAddress = $addressService->getAddress(new AddressData([
    "addressCompanyId" => "CZ12345678",           // Company ID
    "addressCompanyVatId" => "CZ87654321",       // VAT ID
    "addressCompanyName" => "Firma XYZ",         // Company name
    "addressAlias" => "Sídlo",                   // Address alias
    "addressName" => "Josef Novák",              // Contact person name
    "addressStreet" => "Ulice 1234/56",          // Street address
    "addressPostcode" => "12345",                // Postal code
    "addressCity" => "Praha",                    // City
    "addressCountry" => "CZ",                    // Country code
    "addressPhone" => "+420 123 456 789",        // Contact phone
    "addressEmail" => "info@muj-eshop.com"       // Contact email
]));

// Step 3: Use DefaultBuilder to construct the email
$builder = new DefaultBuilder($container);

// Step 4: Build the email content
echo $builder
    ->addHeader("Password Reset")                           // Add a header with the title "Password Reset"
    ->componentLostPassword("Your Website", "https://example.com/reset-password") // Add a block for password reset with the website name and reset link
    ->addFooter($footerAddress)                             // Add a footer with the previously created address
    ->build();                                              // Build and output the final email HTML
```

---

Folders and Structure
---------------------

[](#folders-and-structure)

- `src/` - Contains the main source files of the library:
    - `BlockManager/`
    - `Blocks/`
    - `Collection/`
    - `Context/`
    - `DTO/`
    - `Factories/`
    - `Localization/`
    - `Logger/`
    - `Models/`
    - `Services/`
    - `Template/`
    - `Twig/`
    - `Validators/`
    - `Views/`
    - `ContainerBuilder.php`
- `tests/` - Unit tests for the library, organized by module.
- `demo/` - Contains example implementations for various use cases.

---

Testing
-------

[](#testing)

To run the tests, use the following command:

```
./vendor/bin/phpunit vendor/lemonade/email-generator/tests
```

If you have added PHPUnit to your dependencies, the tests will be executed using the `phpunit.xml` configuration.

---

FAQ
---

[](#faq)

**Q: Can I add attachments to emails?**
A: Yes, attachments are supported as graphical elements (e.g., images) that are linked dynamically via URLs. These URLs are part of the DTO system and can be customized per email.

**Q: Can I use this library with Laravel?**
A: Yes, you can integrate it with Laravel using its built-in service container.

---

Contributing
------------

[](#contributing)

We welcome contributions to this project! To contribute, please follow these steps:

1. Fork this repository.
2. Create a new branch for your changes.
3. Submit your changes via a pull request.

---

License
-------

[](#license)

This project is licensed under the MIT License. For more details, see the [LICENSE](./LICENSE) file.

---

Contact
-------

[](#contact)

For more information or to report an issue, visit the [GitHub repository](https://github.com/johnnyxlemonade/email-generator).

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.6% 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

7

Last Release

518d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c700bffd26445bd0b6d5a6de15fade3c711fa33c924c1f91ef494dac3e44f8c6?d=identicon)[johnnyxlemonade](/maintainers/johnnyxlemonade)

---

Top Contributors

[![johnnyxlemonade](https://avatars.githubusercontent.com/u/3079458?v=4)](https://github.com/johnnyxlemonade "johnnyxlemonade (40 commits)")[![deepsource-io[bot]](https://avatars.githubusercontent.com/in/16372?v=4)](https://github.com/deepsource-io[bot] "deepsource-io[bot] (1 commits)")

---

Tags

emailemail-templateemailgeneratortwig

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lemonade-email-generator/health.svg)

```
[![Health](https://phpackages.com/badges/lemonade-email-generator/health.svg)](https://phpackages.com/packages/lemonade-email-generator)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.4k37.3k](/packages/matomo-matomo)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[symfony/ux-twig-component

Twig components for Symfony

21914.8M162](/packages/symfony-ux-twig-component)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[symfony/ux-live-component

Live components for Symfony

1635.6M72](/packages/symfony-ux-live-component)

PHPackages © 2026

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