PHPackages                             tomazahlin/symfony-mailer-bundle - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. tomazahlin/symfony-mailer-bundle

ActiveSymfony-bundle[Mail &amp; Notifications](/categories/mail)

tomazahlin/symfony-mailer-bundle
================================

Mailer bundle provides a mailer (mail broker) implementation (Swiftmailer wrapper) for Symfony2 framework. It enables you to send mails in a very elegant way while providing extension points for needed modifications.

2.3(8y ago)421.2k↑139.3%2MITPHPPHP &gt;=5.4

Since Apr 13Pushed 8y ago1 watchersCompare

[ Source](https://github.com/tomazahlin/symfony-mailer-bundle)[ Packagist](https://packagist.org/packages/tomazahlin/symfony-mailer-bundle)[ RSS](/packages/tomazahlin-symfony-mailer-bundle/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (3)Dependencies (8)Versions (19)Used By (0)

Symfony2 Mailer Bundle
======================

[](#symfony2-mailer-bundle)

[![Build Status](https://camo.githubusercontent.com/bbefcaf188dc6db09e6ea16856f7972feaf1a45b49fc8b503cf160fd8e42e56d/68747470733a2f2f7472617669732d63692e6f72672f746f6d617a61686c696e2f73796d666f6e792d6d61696c65722d62756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/tomazahlin/symfony-mailer-bundle)

[![SensioLabsInsight](https://camo.githubusercontent.com/58506b9015d54779a885ea39b6c0129d7b2dd52be74fca6003f0f1f87fa12774/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f34666537303939342d636564642d343961612d613033662d3261303138353734643930662f6269672e706e67)](https://insight.sensiolabs.com/projects/4fe70994-cedd-49aa-a03f-2a018574d90f)

This is the explanation of how the bundle is structured and also an installation / example tutorial for the bundle.

Mailer bundle allows you to write very clean code when sending emails. By default it uses Swiftmailer, but if you want, you can override the complete mailer implementation and use some other mailer library. Emails can be forwarded (send) to Swiftmailer directly in the code where you require it, and also if you implement a queueable mailer, sending of the mails can be postponed until Symfony's kernel.terminate event, which is handled after the output is already sent to the user, so the user does not notice the delay of the mailing.

The code is coupled to the Symfony2 framework, as it is presented in the bundle. It might be decoupled later if needed or requested.

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

[](#installation)

### Use composer to require the bundle inside composer.json by running the command:

[](#use-composer-to-require-the-bundle-inside-composerjson-by-running-the-command)

```
php composer.phar require tomazahlin/symfony-mailer-bundle
```

### Enable the bundle in your AppKernel.php

[](#enable-the-bundle-in-your-appkernelphp)

```
public function registerBundles()
{
    $bundles = array(
        // ...
        new Ahlin\Bundle\MailerBundle\AhlinMailerBundle(),
    );
}
```

Run tests
---------

[](#run-tests)

```
bin/phpunit
bin/phpspec run
```

Usage
-----

[](#usage)

[View a controller with examples here](https://github.com/tomazahlin/symfony-mailer-bundle/blob/master/src/Ahlin/Bundle/MailerBundle/Controller/ExampleController.php)

The bundle provides you with the mailing service which gives you access to other services as well, because it uses composition. It exposes one service, so you only have to inject one dependency, preferably the MailingInterface, to keep things decoupled.

```
namespace Company\App;

use Ahlin\Mailer\MailingInterface;

class MyService
{
    private $mailing;

    public function __construct(MailingInterface $mailing)
    {
        $this->mailing = $mailing;
    }

    public function doSomething()
    {
        // How to access factory to create mail instances
        $factory = $this->mailing->getFactory();

        // How to access mailer to send or queue the mail
        $mailer = $this->mailing->getMailer();
    }
}
```

To define your service, you should inject the ahlin\_mailer.mailing service:

```

```

Templates
---------

[](#templates)

To override anything in the bundle, you can of course use bundle inheritance, but for simplicity you can also override some classes by overriding some of the default parameters of the bundle. And to override templates you can define your custom templates in app/Resources.

The bundle is packaged with a default responsive html template:

```
- Resources/views/Mail/default.html.twig

```

You can easily replace the template, by defining your own in app/Resources folder or you can use bundle inheritance to do the same.

To define your own templates, the bundle uses Open for extension / closed for modification solid principle. To define your own templates, you need to create a class and tag it with "ahlin\_mailer.mapping". Let's say you wanted to create a mapping for your UserBundle.

Create a class which implements TemplateMappingInterface.

```
namespace Company\Bundle\UserBundle\Mapping;

use Ahlin\Mailer\Mapping\TemplateMappingInterface;

class UserMapping implements TemplateMappingInterface
{
    public function getMappings()
    {
        return array(
            'registration'      => array('view' => 'CompanyUserBundle:Mail:registration.html.twig',     'contentType' => 'text/html'),
            'activation'        => array('view' => 'CompanyUserBundle:Mail:activation.html.twig',       'contentType' => 'text/html'),
            'forgot_password'   => array('view' => 'CompanyUserBundle:Mail:forgot_password.html.twig',  'contentType' => 'text/html'),
        );
    }
}
```

As you can see, it is only a mapping between aliases and their paths, so when you need to specify which template you want to use, your code will be much shorter and cleaner. And the service definition for the container would look like this:

```

```

You can define (override) the parameters which are always passed to the email templates, by overriding the parameter:

```

    https://localhost

```

In the twig template, you can access it with {{ myHomepageUrl }}.

For any questions or issues regarding this bundle, please do not hesitate to ask. Feel free to create your own forked version or submit any pull requests.

Version 2.2 allows you to add Filters, which modify the email's body. Some filters (if they maybe convert images from url to inline images) also can modify the Swift\_Message model. All you have to do is to implement FilterInterface and tag the filter with "ahlin\_mailer.filter".

Version 2.2 allows you to use the Mailer class to send Swfit\_Message instances.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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 ~71 days

Recently: every ~189 days

Total

17

Last Release

2966d ago

Major Versions

1.1 → 2.02015-05-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/9f6d9e0808a435b875575285b14ab2052017a7685c3f6e591402e2f6dce4e009?d=identicon)[tomazahlin](/maintainers/tomazahlin)

---

Top Contributors

[![fitnessthomas](https://avatars.githubusercontent.com/u/252868116?v=4)](https://github.com/fitnessthomas "fitnessthomas (41 commits)")[![benedyktbla](https://avatars.githubusercontent.com/u/18659685?v=4)](https://github.com/benedyktbla "benedyktbla (1 commits)")

---

Tags

bundlemailSymfony2mailer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tomazahlin-symfony-mailer-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tomazahlin-symfony-mailer-bundle/health.svg)](https://phpackages.com/packages/tomazahlin-symfony-mailer-bundle)
```

###  Alternatives

[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[scullwm/mailhookbundle

A bundle to catch API webhook from differents mail service

4020.5k](/packages/scullwm-mailhookbundle)

PHPackages © 2026

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