PHPackages                             webfiori/mailer - 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. webfiori/mailer

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

webfiori/mailer
===============

Sockets-based library for sending HTML email messages.

2.2.2(1w ago)118.4k[8 issues](https://github.com/WebFiori/mail/issues)1MITPHPPHP &gt;=8.1CI passing

Since Jul 17Pushed 1w ago1 watchersCompare

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

READMEChangelog (10)Dependencies (15)Versions (26)Used By (1)

WebFiori Mailer
===============

[](#webfiori-mailer)

Sockets-based library for sending HTML email messages.

 [ ![](https://github.com/WebFiori/mail/actions/workflows/php84.yaml/badge.svg?branch=main) ](https://github.com/WebFiori/mail/actions/workflows/php84.yaml) [ ![](https://camo.githubusercontent.com/06ff03ef8fe3640865c3b16c4afc5e59f111870f27db0fe9030a89d12b5ae756/68747470733a2f2f636f6465636f762e696f2f67682f57656246696f72692f6d61696c2f6272616e63682f6d61696e2f67726170682f62616467652e737667) ](https://codecov.io/gh/WebFiori/mail) [ ![](https://camo.githubusercontent.com/a0a7cad4979993a16a4627676c361b0fa429e08e622c6719506209d7dfe1e46d/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d57656246696f72695f6d61696c266d65747269633d616c6572745f737461747573) ](https://sonarcloud.io/dashboard?id=WebFiori_mail) [ ![](https://camo.githubusercontent.com/2ee2678818ba45690a5f1c1eb4e6b9e77672393e17178d647ab5817f5cc315a9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f57656246696f72692f6d61696c2e7376673f6c6162656c3d6c6174657374) ](https://github.com/WebFiori/mail/releases) [ ![](https://camo.githubusercontent.com/7e59c17eeacb7b70cc77f5cfbec611004fcf04b66325acaec96ba47b37729699/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77656266696f72692f6d61696c65723f636f6c6f723d6c696768742d677265656e) ](https://packagist.org/packages/webfiori/mailer) [![PHP 8.1+](https://camo.githubusercontent.com/6518db1335bf20fdff07253dc6d6d0cec955b5fb6a8ef1382ac6d73687ecc07f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c7565)](https://camo.githubusercontent.com/6518db1335bf20fdff07253dc6d6d0cec955b5fb6a8ef1382ac6d73687ecc07f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c7565)

Table of Contents
-----------------

[](#table-of-contents)

- [Motivation](#motivation)
- [Supported PHP Versions](#supported-php-versions)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage](#usage)
    - [Basic Usage](#basic-usage)
    - [Fluent Interface](#fluent-interface)
    - [OAuth Authentication](#oauth-authentication)
    - [Attachments](#attachments)
    - [Before Send Callback](#before-send-callback)
    - [After Send Callback](#after-send-callback)
    - [Accessing SMTP Log](#accessing-smtp-log)
    - [Storing Email](#storing-email)
    - [Testing Modes](#testing-modes)
- [Examples](#examples)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)
- [Support](#support)
- [Changelog](#changelog)

Motivation
----------

[](#motivation)

### HTML-First Composition

[](#html-first-composition)

Most mailing libraries treat the email body as a string you pass in. WebFiori Mailer treats emails as **HTML documents you build** using a virtual DOM. You compose emails the same way you'd build a web page — inserting elements, nesting children, setting styles programmatically:

```
$div = $email->insert('div');
$div->addChild('p')->text('Hello!');
$div->addChild('p', ['style' => ['color' => 'red']])->text('Important message.');
```

No raw HTML strings. No template engine required (though templates are supported too).

### Minimal Dependencies

[](#minimal-dependencies)

The library relies only on two lightweight packages (`webfiori/ui` for DOM building and `webfiori/file` for attachments). The SMTP layer is built directly on PHP sockets. No heavy third-party dependencies to keep up with.

### Built-in Testing Modes

[](#built-in-testing-modes)

Testing emails shouldn't require actually sending them or setting up third-party services:

- **Store mode** — Renders the email as a local HTML file for visual inspection, complete with headers metadata.
- **Test send mode** — Redirects messages to specified test addresses regardless of the actual recipients.

Switch between modes with a single call:

```
$email->setMode(SendMode::TEST_STORE, ['store-path' => '/tmp/emails']);
```

### SMTP Transparency

[](#smtp-transparency)

Every command sent to the SMTP server is logged with its response code and message. When something fails, you see exactly what happened at the protocol level — no black-box debugging.

### Lightweight and Self-Contained

[](#lightweight-and-self-contained)

The entire library is a handful of classes. If all you need is to send HTML emails over SMTP without pulling in a large framework or dozens of transitive dependencies, this gets the job done.

Supported PHP Versions
----------------------

[](#supported-php-versions)

Build Status[![](https://github.com/WebFiori/mail/actions/workflows/php81.yaml/badge.svg?branch=main)](https://github.com/WebFiori/mail/actions/workflows/php81.yaml)[![](https://github.com/WebFiori/mail/actions/workflows/php82.yaml/badge.svg?branch=main)](https://github.com/WebFiori/mail/actions/workflows/php82.yaml)[![](https://github.com/WebFiori/mail/actions/workflows/php83.yaml/badge.svg?branch=main)](https://github.com/WebFiori/mail/actions/workflows/php83.yaml)[![](https://github.com/WebFiori/mail/actions/workflows/php84.yaml/badge.svg?branch=main)](https://github.com/WebFiori/mail/actions/workflows/php84.yaml)[![](https://github.com/WebFiori/mail/actions/workflows/php85.yaml/badge.svg?branch=main)](https://github.com/WebFiori/mail/actions/workflows/php85.yaml)Installation
------------

[](#installation)

```
composer require webfiori/mailer
```

Quick Start
-----------

[](#quick-start)

```
