PHPackages                             openclerk/emails - 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. openclerk/emails

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

openclerk/emails
================

A library for sending emails and email management

0.1.2(9y ago)01713PHP

Since Dec 17Pushed 9y ago1 watchersCompare

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

READMEChangelogDependencies (7)Versions (4)Used By (0)

openclerk/emails [![Build Status](https://camo.githubusercontent.com/5756ebca76bc452f7a61ddd3d15fea1cb08344bd0a1b602e69ddaf525d5ea33a/68747470733a2f2f7472617669732d63692e6f72672f6f70656e636c65726b2f656d61696c732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/openclerk/emails)
================================================================================================================================================================================================================================================================================================

[](#openclerkemails-)

A library for sending emails and email management.

Installing
----------

[](#installing)

Include `openclerk/emails` as a requirement in your project `composer.json`, and run `composer update` to install it into your project. Or, run `composer require openclerk/emails`.

```
{
  "require": {
    "openclerk/emails": "^0.1"
  }
}
```

Features
--------

[](#features)

1. Send either text or HTML emails
2. Generate text multipart automatically with [html2text](https://github.com/soundasleep/html2text)
3. Automatically inline CSS styles with [emogrifier](https://github.com/jjriv/emogrifier) for [clients like Gmail](https://litmus.com/blog/understanding-gmail-and-css-part-1)
4. Track e-mails sent with the `email_sent` [event](https://github.com/openclerk/events)
5. Send emails to raw addresses or to User objects that return `getEmail()`

Using
-----

[](#using)

This project uses [openclerk/config](https://github.com/openclerk/config) for config management.

First configure the component with site-specific values (assumes SMTP):

```
Openclerk\Config::merge(array(
  "phpmailer_host" => "mail.example.com",
  "phpmailer_username" => "mailer",
  "phpmailer_password" => "password",
  "phpmailer_from" => "mailer@example.com",
  "phpmailer_from_name" => "Example Mailer",
  "phpmailer_reply_to" => "mailer@example.com",
  "phpmailer_bcc" => "copy@example.com",   // if set, send a copy of all emails to this address

  // optional values
  // "emails_templates" => __DIR__ . "/../emails",
  // "emails_additional_css" => __DIR__ . "/../config/custom.css",
));
```

Now define templates in `emails/.html`:

```
Test email sent {$now}
Hi {$email},

This is a test email sent {$now}.
```

You can optionally specify a wrapping layout HTML file in `emails/layout.html`, and CSS styles in `emails/layout.css`:

```

  {$content}

```

```
html, body {
  background: #eee;
  font-family: 'Arial', sans-serif;
  margin: 0;
  padding: 0;
}
.body {
  background: #eee;
  padding: 15px;
}
.content {
  padding: 15px;
  background: white;
  border: 1px solid #ccc;
  color: #111;
  line-height: 130%;
}
```

Now you can send e-mails immediately:

```
$user = Users\User::findUser(db(), 1);
if (!$user) {
  $user = "test@example.com";
}

$result = Emails\Email::send($user, "", array(
  "now" => date('r'),
));
```

Tracking emails sent
--------------------

[](#tracking-emails-sent)

The `email_sent` [event](https://github.com/openclerk/events) can be used to track emails that have been sent, for example by inserting them into an `emails`[database table](https://github.com/openclerk/db):

```
Openclerk\Events::on('email_sent', function($email) {
  // insert in database keys
  $q = db()->prepare("INSERT INTO emails SET
    user_id=:user_id,
    to_name=:to_name,
    to_email=:to_email,
    subject=:subject,
    template_id=:template_id,
    arguments=:arguments");
  $q->execute(array(
    "user_id" => $email['user_id'],
    "to_name" => $email['to_name'],
    "to_email" => $email['to_email'],
    "subject" => $email['subject'],
    "template_id" => $email['template_id'],
    "arguments" => serialize($email['arguments']),
  ));
});
```

Mock mailing
------------

[](#mock-mailing)

You can set a mock mailer by calling `Emails\Email::setMockMailer($callback)` with a valid callback

```
function setUp() {
  Emails\Email::setMockMailer(array($this, "mockMailer"));
}

function tearDown() {
  Emails\Email::setMockMailer(null);
}

function mockMailer($to_email, $to_name, $subject, $template, $html_template) {
  // do your mock tests...
}
```

TODO
----

[](#todo)

1. Queueing up/batch emails
2. Properly escape templates
3. i18n
4. Failure notifications

Other versions
--------------

[](#other-versions)

1. [actionmailer-html2text](https://github.com/soundasleep/actionmailer-html2text) is a Ruby e-mail framework that automatically generates text multiparts for ActionMailer

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

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

Total

3

Last Release

3413d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ebbec5ccc867054461adebb7c5b6312f8256f989ef96b124892e6e89724afdb?d=identicon)[soundasleep](/maintainers/soundasleep)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/openclerk-emails/health.svg)

```
[![Health](https://phpackages.com/badges/openclerk-emails/health.svg)](https://phpackages.com/packages/openclerk-emails)
```

###  Alternatives

[snowfire/beautymail

Send beautiful html emails with Laravel

1.3k733.1k2](/packages/snowfire-beautymail)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[asahasrabuddhe/laravel-mjml

A package that enables using MJML with Laravel Mailables.

128530.9k](/packages/asahasrabuddhe-laravel-mjml)[terminal42/notification_center

Notification Center extension for Contao Open Source CMS

68396.6k78](/packages/terminal42-notification-center)[markguinn/silverstripe-email-helpers

Silverstripe extension containing SMTP mailer class and some other classes for HTML emails

3145.4k1](/packages/markguinn-silverstripe-email-helpers)[dachcom-digital/emailizr

Pimcore Emailizr - create html emails the right way!

17370.2k4](/packages/dachcom-digital-emailizr)

PHPackages © 2026

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