PHPackages                             brendo/email-template - 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. brendo/email-template

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

brendo/email-template
=====================

Allows for sending of emails using Swift Mailer. Supports Email's and Email Template's

0.2.2(10y ago)06801PHPPHP &gt;=5.4

Since Oct 13Pushed 10y ago2 watchersCompare

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

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

Email Template v0.2.2
=====================

[](#email-template-v022)

[![Build Status](https://camo.githubusercontent.com/681161d72f6aa806be8b2c39d785b1b4813bf85161eeb861c0b65e1396e0c5ab/68747470733a2f2f7472617669732d63692e6f72672f6272656e646f2f656d61696c74656d706c6174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/brendo/emailtemplate)

This component facilitates for the sending of emails using Swiftmailer.

Usage
-----

[](#usage)

This library is made up of a few key concepts. A `Message`, `Prepare` and `Mailer`. All three are required to construct the email, prepare the body and send the email. Optionally, you may also choose to add `Attachment` to your `Message`.

---

### Message

[](#message)

Constructs the bare bones of an email, such as who it's going to, the subject line etc.

#### `Email`

[](#email)

The `Email` class is the most basic of all emails, and simply allows you to create an email with `to`, `cc`, `bcc`, `from`, `subject` and `body` information. The default content type for `Email` messages is 'text/plain'.

```
$email = new EmailTemplate\Message\Email;
$email->to(['your-email@example.com']);
$email->from('system@example.com', 'The Webmaster');
$email->subject('Hello there');
$email->body('Hello there!');

```

#### `EmailTemplate`

[](#emailtemplate)

The `EmailTemplate` class builds on the `Email` class, but instead allows you to load in a template with placeholders. This template is then parsed and prepared with your data to allow you to create dynamic emails. The default content type for `EmailTemplate` messages is `text/html`.

```
$emailTemplate = new EmailTemplate\Message\EmailTemplate('/path/to/email-templates');

// Retrieve your email template (/path/to/email-templates/your-email-template.html)
$emailTemplate->load('your-email-template')

// You can specify a name if you like
$emailTemplate->to(['your-email@example.com' => 'John Smith']);

$emailTemplate->from('system@example.com');
$emailTemplate->subject('Hello there');

```

##### Mesages with Fallback

[](#mesages-with-fallback)

You can specify both plain text and HTML alternatives to an email by specifiying a content type when setting the body of the email:

```
$email->body('This is HTML', 'text/html');
$email->body('This is text', 'text/plain');

```

If the content type is omitted, the default content type will be used (`text/plain` for `Email` and `text/html` for `EmailTemplate`)

---

### Attachment

[](#attachment)

All `Message` classes are able to support attachments via their `attachment` method. An attachment can be either the path to the file, or the actual contents of the file itself. Multiple attachments can be added with subsequent calls to the `attachment` method.

This example is a path to the attachment:

```
// Create the attachment
$attachment = new EmailTemplate\Attachment\Attachment;
$attachment->filename('hello.txt');
$attachment->data('/path/to/your/file', true);

// Now attach it!
$email->attachment($attachment);

```

This example is an inline attachment, an image called `waves.png`. Note the `disposition()` method that will attempt to inline the image instead of just attaching it to the message.

```
// Create the attachment
$attachment = new EmailTemplate\Attachment\Attachment;
$attachment->filename('waves.png');
$attachment->data({wavesbinarydatahere});
$attachment->contentType('image/png');
$attachment->disposition('inline');

// Now attach it!
$email->attachment($attachment);

```

---

### Prepare

[](#prepare)

This is what generates the actual body of an email template. It should be used in conjuction with `Message\EmailTemplate`.

#### `VsprintPrepare`

[](#vsprintprepare)

This is a very simple handler, which accepts the template and an array of parameters to be included.

It can be used standalone:

```
$prepare = new \EmailTemplate\Prepare\VsprintfPrepare();
$parsed = $prepare->render('Hi %s', array('there'));

```

Or assuming `$emailTemplate` from the above example:

```
// This will be used to replace the placeholders in the template
$emailTemplate->prepare(new \EmailTemplate\Prepare\VsprintfPrepare(), ['Brendan']);

// Or you can inject the parsed template
$emailTemplate->setParsedTemplate($parsed);

```

#### `MustachePrepare`

[](#mustacheprepare)

This allows you to markup your template using [Mustache](http://mustache.github.io/).

It can be used standalone:

```
$prepare = new \EmailTemplate\Prepare\MustachePrepare();
$parsed = $prepare->render('Hi {{name}}', array('name' => 'there'));

```

Assuming `$emailTemplate` from the above example:

```
// This will be used to replace the placeholders in the template
$emailTemplate->prepare(new \EmailTemplate\Prepare\MustachePrepare(), ['Brendan']);

// Or you can inject the parsed template
$emailTemplate->setParsedTemplate($parsed);

```

---

### Mailer

[](#mailer)

This is how the emails will actually be sent.

#### `SwiftMailer`

[](#swiftmailer)

For the moment, sending of Emails is abstracted to use the `Swiftmailer` class.

```
// Now lets prepare the mailer
$mailer = new \EmailTemplate\Mailer();

// Set the mail configuration
$mailer->setConfiguration([
    'host' => 'your host',
    'port' => 'your port'
    'user' => 'your username',
    'password' => 'your password'
]);

// If you want logging, you can pass a Monolog handler to do so
$mailer->setLogger($logger);

// The mailer can handle any email that implements the MessageInterface
$mailer->send($email); // This can also be $emailTemplate

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

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

Total

4

Last Release

4009d ago

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/brendo-email-template/health.svg)

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

###  Alternatives

[symfony/mailer

Helps sending emails

1.6k368.1M953](/packages/symfony-mailer)[symfony/notifier

Sends notifications via one or more channels (email, SMS, ...)

80640.3M290](/packages/symfony-notifier)[zbateson/mail-mime-parser

MIME email message parser

53949.2M79](/packages/zbateson-mail-mime-parser)[illuminate/mail

The Illuminate Mail package.

5910.1M391](/packages/illuminate-mail)[cspoo/swiftmailer-mailgun-bundle

Swiftmailer Mailgun bundle

1031.1M](/packages/cspoo-swiftmailer-mailgun-bundle)[dotdigital/dotdigital-magento2-extension

Dotdigital for Magento 2

50374.2k18](/packages/dotdigital-dotdigital-magento2-extension)

PHPackages © 2026

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