PHPackages                             mouf/utils.mailer.mail-interface - 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. mouf/utils.mailer.mail-interface

ActiveMouf-library[Mail &amp; Notifications](/categories/mail)

mouf/utils.mailer.mail-interface
================================

This package contains interfaces and classes describing mails. It also contains the MailerService interface that should be implemented by any service that can send mails. You should use a package implementing this interface (like the SmtpMailer package.

v2.2.0(8y ago)047.3k5[1 PRs](https://github.com/thecodingmachine/utils.mailer.mail-interface/pulls)4MITPHPPHP &gt;=5.3.0

Since Jul 21Pushed 8y ago12 watchersCompare

[ Source](https://github.com/thecodingmachine/utils.mailer.mail-interface)[ Packagist](https://packagist.org/packages/mouf/utils.mailer.mail-interface)[ Docs](https://github.com/thecodingmachine/utils.mailer.mail-interface)[ RSS](/packages/mouf-utilsmailermail-interface/feed)WikiDiscussions 2.2 Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (7)Used By (4)

[![Latest Stable Version](https://camo.githubusercontent.com/2150fc304a4dbbe39109898e3041332f088a450f685ab160e5984dfab1249886/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f7574696c732e6d61696c65722e6d61696c2d696e746572666163652f762f737461626c652e737667)](https://packagist.org/packages/mouf/utils.mailer.mail-interface)[![Latest Unstable Version](https://camo.githubusercontent.com/36a9cfc1ddeb7a4d4560d87d540154ee9c3af2b60721abe8ff4f27d21ccaa992/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f7574696c732e6d61696c65722e6d61696c2d696e746572666163652f762f756e737461626c652e737667)](https://packagist.org/packages/mouf/utils.mailer.mail-interface)[![License](https://camo.githubusercontent.com/3e42b05870f301eefd64f38d8e6b715d9d75c27752e5af8734c21d34b548190c/68747470733a2f2f706f7365722e707567782e6f72672f6d6f75662f7574696c732e6d61696c65722e6d61696c2d696e746572666163652f6c6963656e73652e737667)](https://packagist.org/packages/mouf/utils.mailer.mail-interface)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e3196cac04815da778f61bb5587966ae8025a3b8b0cd13ce9beac884f4a1d58f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f7574696c732e6d61696c65722e6d61696c2d696e746572666163652f6261646765732f7175616c6974792d73636f72652e706e673f623d322e30)](https://scrutinizer-ci.com/g/thecodingmachine/utils.mailer.mail-interface/?branch=2.1)

Mouf Mail system
================

[](#mouf-mail-system)

The Mouf framework is only an IOC framework. As such, it does not provide any means for managing any kind of cache. Hopefully, the Mouf team provides also a range of packages to manage sending mails.

The mail architecture
---------------------

[](#the-mail-architecture)

In Mouf, *emails* are sent using *MailServices*.
Mouf provides 4 implementations of mail services. You can provide your own if you want.

By default, Mouf provides these 3 implementations:

- [**SwiftMailService**](http://mouf-php.com/packages/mouf/utils.mailer.swift-mail-service/README.md): a mail service that uses a SMTP server to send mails (this is a wrapper using the Swift mail library).
- [**SmtpMailService**](http://mouf-php.com/packages/mouf/utils.mailer.smtp-mail-service/README.md): a mail service that uses a SMTP server to send mails (this is a wrapper using the Zend\_Mail library).
- [**DBMailService**](http://mouf-php.com/packages/mouf/utils.mailer.db-mail-service/README.md): a mail service that does not send any mails. Instead, it writes the mail in a MySQL database. It can forward the mail later to another mail service that will actually send the mail. This mail server is available in the package *utils/mailer/db-mail-service*.

Each mail service must extend the `MailServiceInterface` interface that is part of the package utils/mailer/mail-interface.

The mail service interface
--------------------------

[](#the-mail-service-interface)

Each class implementing the `MailServiceInterface` provides one simple method to send mails:

```
interface MailServiceInterface {

	/**
	 * Sends the mail passed in parameter.
	 *
	 * @param MailInterface $mail The mail to send.
	 */
	function send(MailInterface $mail);
}
```

The mail passed in parameter must implement the `MailInterface` interface. Hopefully, Mouf provides a `Mail` class that does just that!

For instance, to send a mail, you just need to write:

```
$mailService = Mouf::getSmtpMailService();

$mail = new Mail();
$mail->setBodyText("This is my mail!");
$mail->setBodyHtml("This is my &lt;b&gt;mail&lt;/b&gt;!");
$mail->setFrom(new MailAddress("my@server.com", "Server"));
$mail->addToRecipient(new MailAddress("david@email.com", "David"));
$mail->setTitle("My mail");

$mailService->send($mail);
```

The code above assumes that you configured an instance in Mouf called "smtpMailService".

The `MailInterface` interface supports:

- Text/Html mails (`setBodyText` and `setBodyHtml` methods)
- Multiple recipients (`addToRecipient` method)
- Multiple Cc recipients (`addCcRecipient` method)
- Multiple Bcc recipients (`addBccRecipient` method)
- File attachments (`addAttachment` method)

Mail addresses are passed as a `MailAddress` object, that contains 2 strings: the mail address and the alias.

Automatic text body generation
------------------------------

[](#automatic-text-body-generation)

When sending mails, it is a good practice to send 2 *bodies*: one in **plain text** and one in **HTML**. Forget the **plain text** and your mail could be flagged as spam. However, most of the time, your users will look at the mail in HTML. Mail clients that can only read plain text are really rare those days.

The `Mail` class can help you here. Indeed, it will automatically generate the plain text version of your mail from the HTML, by stripping all tags.

```
$mail = new Mail();
$mail->setBodyHtml("This is my &lt;b&gt;mail&lt;/b&gt;!");
// No need to call $mail->setBodyText()
```

If you want to explicitly disable the plain text generation you can call this method:

```
$mail = new Mail();
$mail->setBodyHtml("This is my &lt;b&gt;mail&lt;/b&gt;!");
// Disable plaing text generation from HTML. The mail will NOT contain the plain text part.
$mail->autoCreateBodyText(false);
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 90% 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 ~169 days

Recently: every ~252 days

Total

7

Last Release

2937d ago

Major Versions

2.0.x-dev → 3.0.x-dev2015-07-30

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

---

Top Contributors

[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (9 commits)")[![xhuberty](https://avatars.githubusercontent.com/u/8350192?v=4)](https://github.com/xhuberty "xhuberty (1 commits)")

---

Tags

mailinterfacemailermouf

### Embed Badge

![Health badge](/badges/mouf-utilsmailermail-interface/health.svg)

```
[![Health](https://phpackages.com/badges/mouf-utilsmailermail-interface/health.svg)](https://phpackages.com/packages/mouf-utilsmailermail-interface)
```

###  Alternatives

[nette/mail

📧 Nette Mail: A handy library for creating and sending emails in PHP.

5389.8M246](/packages/nette-mail)[voku/bounce-mail-handler

Bounce Mail Handler

49230.9k2](/packages/voku-bounce-mail-handler)[boundstate/yii2-mailgun

Mailgun integration for the Yii framework

28160.6k](/packages/boundstate-yii2-mailgun)[sandstorm/templatemailer

Neos and Flow package for simple handling of template-based emails, including CSS inlining

1147.3k2](/packages/sandstorm-templatemailer)[yzh52521/think-mail

A powerful and beautiful php mailer for All of ThinkPHP and Other PHP Frameworks based symfony

745.0k](/packages/yzh52521-think-mail)[yarcode/yii2-mailgun-mailer

Mailgun mailer implementation for Yii2

1576.0k](/packages/yarcode-yii2-mailgun-mailer)

PHPackages © 2026

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