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

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

wpjscc/mail
===========

Simple, modern library of services for sending UTF-8 e-mail

01↓100%PHP

Since May 8Pushed 1mo agoCompare

[ Source](https://github.com/wpjscc/mail)[ Packagist](https://packagist.org/packages/wpjscc/mail)[ RSS](/packages/wpjscc-mail/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

kodus/mail
==========

[](#kodusmail)

[![PHP Version](https://camo.githubusercontent.com/487804500a039aee09e5d93e41b745b4cd68dcc0fdf801e67d26d30b93f83358/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e302532422d626c75652e737667)](https://packagist.org/packages/kodus/mail)[![Build Status](https://camo.githubusercontent.com/2fb9d8ad00fe7267d9e8c7953c022a12dc8a1171040b8c3690f28951e04680bc/68747470733a2f2f7472617669732d63692e6f72672f6b6f6475732f6d61696c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kodus/mail)[![Code Coverage](https://camo.githubusercontent.com/e8abf7ce2dc9e6a7e48daba0a2ad283e48abed46290bfbd065aee84a500e6296/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b6f6475732f6d61696c2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/kodus/mail/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/753466cf77616e74088e6ac66c56eb094cca2691a7b5ee5d5c8435326f71f382/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b6f6475732f6d61696c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/kodus/mail/?branch=master)

[Simple](#objectives) services for sending UTF-8 e-mail.

See [UPGRADING.md](UPGRADING.md) for upgrade instructions.

Features
--------

[](#features)

- SMTP client supports username/password authentication and secure (SSL) sockets.
- Sends MIME-compliant multi-part text/HTML e-mails.
- Handles large attachments using streams for predictable, low memory usage.
- Attachments from memory or from any stream-wrapper.
- Support for inline (image) attachments.
- Multiple recipients for all types of recipient fields.
- Sends multiple e-mails without reconnecting.

### Non-Features

[](#non-features)

Some features are delibarely outside the scope of this project:

- Support for arbitrary character sets is omitted - all modern mail clients support UTF-8.
- No support for `mail()` as a transport method, as this function has constraints that conflict with our objectives - mainly, it does not support streams, which means the entire message has to fit in memory, which leads to unpredictable performance and memory usage.

Overview
--------

[](#overview)

Mail service implementations are abstracted behind the `MailService` interface, which depends on the `Message` model to define the actual content.

To send mail, simply create an instance of `Message`, populate it with new instances of `Address`and `Attachment` models by calling various public set/add-methods, then call `MailService::send()`.

The model permits any combination of UTF-8 text and HTML message bodies with any number of attachments.

Usage
-----

[](#usage)

The following example assumes a `MailService` instance named `$service` is in scope - subsequent sections will explain how to configure an e-mail service.

Here's an example of sending a plain-text e-mail with an attachment:

```
$message = new Message(
    new Address($email),        // recipient
    new Address("me@test.org"), // sender
    "Hello, Person!",           // subject
    $text                       // plain text message body
);

$message->addAttachment(Attachment::fromFile(__DIR__ . "/awsum/unicorns.gif"));

$service->send($message);
```

Refer to the [`Message`](src/Message.php) model to learn about additional message properties.

SMTP Mail Service
-----------------

[](#smtp-mail-service)

The `SMTPMailService` implementation connects directly to an SMTP server via sockets.

To bootstrap an SMTP mail service, you need to select your `Connector` and `Authenticator`implementations - for example:

```
$service = new SMTPMailService(
    new SocketConnector("localhost", 25),
    new LoginAuthenticator("user", "super_secret_pa55w0rd"),
    "test.org"
);
```

Note the third argument, which is the local host-name - this is used in the handshake (`EHLO`) message send to the SMTP server when the client connects.

SMTP protocol-level logging is supported for diagnostic purposes, and can be enabled by injecting a [PSR-3 Logger](http://www.php-fig.org/psr/psr-3/) into `SMTPClient` via `SMTPClient::setLogger()` - this may be useful if you have connection issues, as it will write a `debug`-level entry for every SMTP command sent, and every response received.

### `examples/send.php`

[](#examplessendphp)

The repository includes a small runnable script that sends two sample messages (plain text and HTML) through QQ Mail’s SMTP endpoint (`smtp.qq.com`, port `587`, `STARTTLS` via `SecureSocketConnector`). It uses [React Async](https://github.com/reactphp/async) because the SMTP client integrates with the React event loop.

From the project root, after `composer install`:

```
php examples/send.php
```

- **account**: SMTP login address (also used as the `From` address in the sample messages).
- **password**: SMTP password (for QQ Mail this is usually an application-specific authorization code, not your normal login password).
- **to@address**: Recipient address.

The EHLO client domain is derived from the part of the account address after `@`. Adjust host, port, or provider in the script if you use another SMTP server.

The script calls `SMTPMailService::disconnect()` after sending so the underlying client closes with `QUIT`.

Message Logging
---------------

[](#message-logging)

Unlike SMTP protocol-level logging described above, a more general logging facility is also available - this will write a single log-entry on success or failure to send a message, and is more generally applicable to any `MailService` implementation, including of course the SMTP service.

To write a log-entry to a [PSR-3 Logger](http://www.php-fig.org/psr/psr-3/), use the `MailSeviceLogger`implementation, which acts as a decorator for any other `MailService` implementation - for example:

```
$service = new MailServiceLogger($psr_logger, new SMTPMailService(...));
```

See inline documentation for `MailServiceLogger` for details on customizing the message template and log-level.

Passive Mail Service
--------------------

[](#passive-mail-service)

A passive implementation of `MailService` is available, which does nothing.

You can use this during testing/development to disable any outgoing Messages.

This is typically most useful in conjunction with the `MailServiceLogger` described above, to bootstrap a fake mail-service for testing and development, enabling you to see Messages that *would* have been sent.

Development
-----------

[](#development)

To run the integration tests, you will need to set up a local SMTP server for testing.

To make sure `SecureSocketCest` passes your SMTP server also needs to have TLS support with a SSL certificate.

It is recommended to use [smtp4dev](https://github.com/rnwood/smtp4dev) since it has cross-platform support and can generate its own self-signed SSL certificate.

When configuring smtp4dev make sure to set `TlsMode` to `StartTls`, this ensures that TLS is only used when the client asks for it, setting it to `ImplicitTls` will likely make all non-TLS tests fail.

When starting the smtp4dev server it should tell you where the generated certificate is stored, you'll need to add this to your systems trusted CA store.

You may need to copy `integration.suite.dist.yml` to `integration.suite.yml` to customize the SMTP host-name, port-number, etc.

Objectives
----------

[](#objectives)

This library has a number of stated design objectives:

- Simplicity: UTF-8 is the only supported character-set, we make an effort not to reinvent the wheel (e.g. leveraging base64 and quoted-printable stream-filters) and the library has no external dependencies.
- Using streams for efficiency and predictable memory usage - in particular, file attachments are encoded and sent in chunks, without buffering the entire message or juggling huge strings.
- Separation of concerns - in particular, MIME encoding and SMTP transport concerns ("[dot-stuffing](https://tools.ietf.org/html/rfc5321#section-4.5.2)") are fully separated, which in turn is made possible by proper use of streams.
- Using dependency injection (primarily constructor injection) everywhere.
- Using abstractions (interfaces) both at the high level and for dependencies/components.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance61

Regular maintenance activity

Popularity2

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 76.8% 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.

### Community

Maintainers

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

---

Top Contributors

[![mindplay-dk](https://avatars.githubusercontent.com/u/103348?v=4)](https://github.com/mindplay-dk "mindplay-dk (63 commits)")[![vortrixs](https://avatars.githubusercontent.com/u/15426116?v=4)](https://github.com/vortrixs "vortrixs (5 commits)")[![jrmoller](https://avatars.githubusercontent.com/u/4255227?v=4)](https://github.com/jrmoller "jrmoller (3 commits)")[![thomasnordahl-dk](https://avatars.githubusercontent.com/u/5709900?v=4)](https://github.com/thomasnordahl-dk "thomasnordahl-dk (3 commits)")[![jakejohns](https://avatars.githubusercontent.com/u/174708?v=4)](https://github.com/jakejohns "jakejohns (2 commits)")[![rhl-jfm](https://avatars.githubusercontent.com/u/12860072?v=4)](https://github.com/rhl-jfm "rhl-jfm (2 commits)")[![sunkan](https://avatars.githubusercontent.com/u/568492?v=4)](https://github.com/sunkan "sunkan (2 commits)")[![wpjscc](https://avatars.githubusercontent.com/u/76907477?v=4)](https://github.com/wpjscc "wpjscc (1 commits)")[![hanzi](https://avatars.githubusercontent.com/u/1106400?v=4)](https://github.com/hanzi "hanzi (1 commits)")

### Embed Badge

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

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

###  Alternatives

[mattketmo/email-checker

Throwaway email detection library

2742.1M5](/packages/mattketmo-email-checker)[ifightcrime/bootstrap-growl

Pretty simple jQuery plugin that turns standard Bootstrap alerts into 'Growl-like' notifications.

80113.0k](/packages/ifightcrime-bootstrap-growl)[sarfraznawaz2005/noty

Laravel package to incorporate noty flash notifications into laravel.

324.5k](/packages/sarfraznawaz2005-noty)[andheiberg/notify

A site notification package for laravel.

119.1k1](/packages/andheiberg-notify)

PHPackages © 2026

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