PHPackages                             krs/mail-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. krs/mail-bundle

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

krs/mail-bundle
===============

Symfony2 MailBundle.

050PHP

Since Jan 17Pushed 12y ago7 watchersCompare

[ Source](https://github.com/AKarismatik/KRSMailBundle)[ Packagist](https://packagist.org/packages/krs/mail-bundle)[ RSS](/packages/krs-mail-bundle/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

KRSMailBundle
=============

[](#krsmailbundle)

The symfony2 KRSMailBundle provide an easy way to manage application email templates.

Features include:

- Manage Email Templates
- Generate Sonata Admin

Getting started with KRSMailBundle
==================================

[](#getting-started-with-krsmailbundle)

The symfony2 KRSMailBundle provide an easy way to manage application email templates. Mail templates

When sending a mail with symfony, you generally write the mail body in a file template. The mail subject is also frequently hard-coded in an action, as well as "from" and "to" emails. The problem is that the developper is responsible for writing and maintaining all these values. Each time the customer wanna change the mail body, he depends on the developper.

The goal is to let a non-developper manage sent mails, by moving all mail attributes from the code to the database.

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

[](#installation)

### Step 1: Download KRSMailBundle using composer

[](#step-1-download-krsmailbundle-using-composer)

Add KRSMailBundle in your composer.json:

```
{
    "require": {
       "krs/mail-bundle": "dev-master"
    }
}
```

Now tell composer to download the bundle by running the command:

```
$ php composer.phar update krs/mail-bundle
```

Composer will install the bundle to your project's `vendor/krs` directory.

### Step 2: Enable the bundle

[](#step-2-enable-the-bundle)

```
public function registerBundles()
{
    $bundles = array(
        // ...
        new KRS\MailBundle\KRSMailBundle(),
    );
}
```

Send a mail using a mail template
---------------------------------

[](#send-a-mail-using-a-mail-template)

Mails are generally sent from a symfony action. Suppose you want to send a mail to a registered user when (s)he signs up a petition.

```
$this->get('krs.mailer')                 // get a KRSMail instance
->setTemplate('karis_mail_confirmation') // choose a KRSMailTemplate
->addValues(array(                          // add values to populate the template
  'user_name'       => $user->username,
  'user_email'      => $user->email,
  'petition_name'   => $petition->name
))
->send();
```

The first time your run this code, the "karis\_mail\_confirmation" mail template does not exist, and gets created automatically.

Configure the template
----------------------

[](#configure-the-template)

Now you need to modify it in Admin-&gt;Tools-&gt;Mail templates. A Mail template has the following fields:

### Name

[](#name)

The unique name of the template, used in your PHP code to identify it. eg. "sign\_petition\_confirmation"

\###Description

Short description to help you remember what this mail template is used to. eg. "Congrat a user who just signed up a petition"

Active

Whether to send emails that use this template or not.

### Subject

[](#subject)

The one-line mail subject. eg. "Hello, dear %user\_name%"

### Body

[](#body)

The mail body. eg. "Thanks for signing the petition %petition\_name%!"

### From Email

[](#from-email)

The "from" header of the mail. eg.

`webmaster@mysite.com `you can use several email adresses, both static and variables one, and provide both name and email.

`other-mail@domain.com, %user_email%, Sergio `

### To Email

[](#to-email)

The email, or list of emails, that will receive the mail. eg.

`%user_email% `

### The variables

[](#the-variables)

When you configure a mail template with the admin interface, you see the available variables you can use in the template fields. With the current example, you can use the variables: %user\_name%, %user\_email%, %petition\_name%. You don't need to manage manually this list of available variables. They are automatically updated if needed when you render a mail, using the values array:

```
->addValues(array(                        // add values to populate the template
  'user_name'       => $user->username,
  'user_email'      => $user->email,
  'petition_name'   => $petition->name
))

```

More ways to pass values

In the previous example, we pass values to the template with a simple PHP array:

```
->addValues(array(                        // add values to populate the template
  'user_name'       => $user->username,
  'user_email'      => $user->email,
  'petition_name'   => $petition->name
))

/*
 * Values available in the template:
 * %user_name%, %user_email%, %petition_name%
 */

```

You can also use a Doctrine record or a Doctrine form. In this case, the table columns are used as keys, and the object values as values.

```
->addValues($user) // $user is an instance of the DmUser model, which extends DoctrineRecord
/*
 * Values available in the template:
 * %username%, %email%, %is_active%, ...
 */
You can call the addValues() method several times, and pass it a prefix as a second argument:

->addValues($user, 'user_')
->addValues($petition, 'petition_')
->addValues(array(
  'petition_url' => $this->getHelper()->link($petition)->getAbsoluteHref()
))

/*
 * Values available in the template:
 * %user_username%, %user_email%, %user_is_active%, %petition_name%, %petition_text%, %petition_url%
 */

```

[![Bitdeli Badge](https://camo.githubusercontent.com/c79b26a711f3f5cf439a8fae14607d647f92971206d79c503ca68f3e2843b3f4/68747470733a2f2f64327765637a68766c38323376302e636c6f756466726f6e742e6e65742f414b617269736d6174696b2f6b72736d61696c62756e646c652f7472656e642e706e67)](https://bitdeli.com/free "Bitdeli Badge")

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

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

---

Top Contributors

[![adala-khaled](https://avatars.githubusercontent.com/u/189445476?v=4)](https://github.com/adala-khaled "adala-khaled (4 commits)")[![zameur](https://avatars.githubusercontent.com/u/5918378?v=4)](https://github.com/zameur "zameur (4 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![fatmah](https://avatars.githubusercontent.com/u/3702700?v=4)](https://github.com/fatmah "fatmah (1 commits)")

### Embed Badge

![Health badge](/badges/krs-mail-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/krs-mail-bundle/health.svg)](https://phpackages.com/packages/krs-mail-bundle)
```

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M227](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

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