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.1.0(7mo ago)116.4kMITPHPPHP &gt;=8.1CI passing

Since Jul 17Pushed 7mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (21)Used By (0)

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

[](#webfiori-mailer)

A powerful and easy-to-use PHP library for sending HTML-based emails with SMTP support, OAuth authentication, and advanced features.

 [ ![](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)

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)In This Page:
-------------

[](#in-this-page)

- [Installation](#installation)
- [Examples](#examples)
- [Usage](#usage)
    - [Basic Usage](#basic-usage)
        - [Connecting to SMTP Server](#connecting-to-smtp-server)
        - [Creating Email Message](#creating-email-message)
        - [Setting Email Subject](#setting-email-subject)
        - [Adding a Recipient](#adding-a-recipient)
        - [Writing Some Text](#writing-some-text)
        - [Sending The Message](#sending-the-message)
        - [All Together](#all-together)
    - [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)
- [Setup Testing](#setup-testing)

Installation
------------

[](#installation)

Install via Composer:

```
composer require webfiori/mailer
```

Examples
--------

[](#examples)

Comprehensive examples are available in the [`examples/`](examples/) directory:

- **[Basic Usage](examples/basic-usage/)** - Fundamental email sending and fluent interface
- **[OAuth Authentication](examples/oauth-usage/)** - Gmail and Microsoft OAuth integration
- **[File Attachments](examples/attachments/)** - Adding files to emails
- **[Sending Modes](examples/sending-modes/)** - Test, development, and production configurations
- **[SMTP Logging](examples/accessing-log/)** - Debugging and monitoring
- **[Callbacks](examples/callbacks/)** - Before/after send custom logic

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

This section describes most basic use case of the library. It shows how to connect to SMTP server, writing a message and sending it to specific address.

#### Connecting to SMTP Server

[](#connecting-to-smtp-server)

Connection information are represented using an instance of the class [`WebFiori\Mail\SMTPAccount`](https://github.com/WebFiori/mail/blob/main/WebFiori/Mail/SMTPAccount.php).

```
