PHPackages                             genilto/sbmailer - 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. genilto/sbmailer

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

genilto/sbmailer
================

A small layer created to abstract the ways to send emails with php.

4.0.0(3y ago)032MITPHP

Since Jun 19Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/genilto/sbmailer)[ Packagist](https://packagist.org/packages/genilto/sbmailer)[ Docs](https://github.com/genilto/sbmailer)[ RSS](/packages/genilto-sbmailer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (16)Used By (0)

SBMailer
========

[](#sbmailer)

A small layer created to abstract the ways to send emails with php.

Email Adapters
--------------

[](#email-adapters)

This project contains a small abstraction for email sending process. It uses adapters to allow the implementation of any email sending provider. Currently, there are some adapters implemented, as below.

The first step is require the sbmailer package to your project:

```
composer require genilto/sbmailer
```

After that, you must install the corresponding SDK according to the adapter you are going to use, and then configure as default adapter.

To do that, you must define a constant named SBMAILER and set the default parameters.

See the examples bellow.

### Postmark

[](#postmark)

Send emails using the Postmark API library.

To use this adapter you must require the following dependencies in your project:

```
composer require wildbit/postmark-php
```

And then configure the default adapter like bellow:

```
define('SBMAILER', array(
    'default' => 'postmark',
    'params' => array (
        'postmark' => array (
            'api_key' => getenv('POSTMARK_API_KEY')
        )
    )
));
```

### PHPMailer

[](#phpmailer)

Send emails using the PHPMailer library. This particular adapter allow you to not inform params, so PHPMailer will use php mail() function to send emails.

To use this adapter you must require the following dependencies in your project:

```
composer require phpmailer/phpmailer
```

And then configure the default adapter like bellow:

#### Send Using mail() function

[](#send-using-mail-function)

```
define('SBMAILER', array(
    'default' => 'phpmailer'
));
```

#### Send Using SMTP

[](#send-using-smtp)

```
define('SBMAILER', array(
    'default' => 'phpmailer',
    'params' => array (
        'phpmailer' => array ( // Using SMTP function
            'smtp_server'   => getenv('MAIL_SMTP_SERVER'),
            'smtp_port'     => getenv('MAIL_SMTP_PORT'),
            'smtp_user'     => getenv('MAIL_SMTP_USER'),
            'smtp_password' => getenv('MAIL_SMTP_PASSWORD')
        ),
    )
));
```

### Sendgrid

[](#sendgrid)

Send emails using the Sendgrid API library.

To use this adapter you must require the following dependencies in your project:

```
composer require sendgrid/sendgrid
```

And then configure the default adapter like bellow:

```
define('SBMAILER', array(
    'default' => 'sendgrid',
    'params' => array (
        'sendgrid' => array (
            'api_key' => getenv('SENDGRID_API_KEY')
        ),
    )
));
```

### Mailersend

[](#mailersend)

Send emails using the Mailersend API library.

To use this adapter you must require the following dependencies in your project:

```
composer require php-http/guzzle7-adapter nyholm/psr7
composer require mailersend/mailersend
```

And then configure the default adapter like bellow:

```
define('SBMAILER', array(
    'default' => 'mailersend',
    'params' => array (
        'mailersend' => array (
            'api_key' => getenv('MAILERSEND_API_KEY')
        )
    )
));
```

### Sendinblue

[](#sendinblue)

Send emails using the Sendinblue API library.

To use this adapter you must require the following dependencies in your project:

```
composer require sendinblue/api-v3-sdk
```

And then configure the default adapter like bellow:

```
define('SBMAILER', array(
    'default' => 'sendinblue',
    'params' => array (
        'sendinblue' => array (
            'api_key' => getenv('SENDINBLUE_API_KEY')
        )
    )
));
```

### Microsoft Graph

[](#microsoft-graph)

Send emails using the Microsoft Graph API library.

To use this adapter you must require the following dependencies in your project:

```
composer require microsoft/microsoft-graph
```

And then configure the default adapter like bellow:

```
define('SBMAILER', array(
    'default' => 'microsoft-graph',
    'params' => array (
        'microsoft-graph' => array (
            'tenant_id' => getenv('MS_GRAPH_TENTANT_ID'),
            'client_id' => getenv('MS_GRAPH_CLIENT_ID'),
            'client_secret' => getenv('MS_GRAPH_CLIENT_SECRET'),
            'save_to_sent_items' => true,
        )
    )
));
```

Test environment
----------------

[](#test-environment)

The library allow you to set the environment as test. That means that you can define a default email address where the emails will be redirected when in test environment.

Below is an example of an entire configuration, with multiple email providers and defining postmark as the default email. Also, defining the environment as test, with a default email and name where all the test emails will be delivered.

```
define('SBMAILER', array (
    'default' => getenv('DEFAULT_ADAPTER'),
    //'log_location' => '',
    'params'  => array (
        'postmark' => array (
            'api_key' => getenv('POSTMARK_API_KEY')
        ),
        'sendgrid' => array (
            'api_key' => getenv('SENDGRID_API_KEY')
        ),
        'mailersend' => array (
            'api_key' => getenv('MAILERSEND_API_KEY')
        ),
        'sendinblue' => array (
            'api_key' => getenv('SENDINBLUE_API_KEY')
        ),
        // 'phpmailer' => array (), // Using mail function
        'phpmailer' => array ( // Using SMTP function
            'smtp_server'   => getenv('MAIL_SMTP_SERVER'),
            'smtp_port'     => getenv('MAIL_SMTP_PORT'),
            'smtp_user'     => getenv('MAIL_SMTP_USER'),
            'smtp_password' => getenv('MAIL_SMTP_PASSWORD')
        ),
        'microsoft-graph' => array (
            'tenant_id' => getenv('MS_GRAPH_TENTANT_ID'),
            'client_id' => getenv('MS_GRAPH_CLIENT_ID'),
            'client_secret' => getenv('MS_GRAPH_CLIENT_SECRET'),
            'save_to_sent_items' => true,
        ),
    ),
    'log_level' => getenv('LOG_LEVEL'), // 0 - Off | 1 - Error only | 2 - Full
    'env' => getenv('ENV'), // 'prod' or 'test'
    'test_address' => getenv('TEST_ADDRESS'), // Required when env == 'test'
    'test_address_name' => getenv('TEST_ADDRESS_NAME'),
));
```

Setting 'env' as 'test' it will be required that you set test\_address as well. All messages will be redirected to the test\_address and a message with all recipients will be appended to the message body.

How to implement new Adapters
-----------------------------

[](#how-to-implement-new-adapters)

You can implement new adapters just implementing the interface iSBMailerAdapter giving it a unique name and class name. See the existing adapters to a better undertanding.

Setup before run the examples
-----------------------------

[](#setup-before-run-the-examples)

Before run the examples, you need to install the dependencies of each adapter you intend to use.

This project install the dependencies using composer. Make sure you have composer installed.

Install all the dependencies as described above.

In developer environments, just run:

```
composer install
```

All the dependencies for all the adapters will be installed.

How to run the example
----------------------

[](#how-to-run-the-example)

You can run directly using some local server, as apache and php, just pointing the server to html folder of the project.

Or you can run it using docker. There is a docker-composer.yml in the project that creates a container, pointing the server to the html folder of the project.

Before run the composer, duplicate the file env.sample and rename to .env. After that configure the environment variables there with the correct values.

To create the container just use the command below in your terminal:

```
docker-compose up -d
```

To test the example, just go to  in your browser. If you have configured the correct informations, you can use the form to send a test email.

Manually Install and use in production
--------------------------------------

[](#manually-install-and-use-in-production)

Download the latest release file (zip) from github releases. Unzip in your server and import sbmailer/SBMailer.php in your code. It would require all it needs to run.

For production
--------------

[](#for-production)

For production, you must run:

```
composer install --no-dev
```

Just basic dependencies will be installed, and you must require the desired dependency as described above.

You must remove the html folder from the final version that goes into production case it is there. It contains a form to test email sendings, and it is not good let it it public in your server.

By the way, the suggestion is keeping this library out of public directory, and just requiring sbmailer/SBMailer.php in your code.

Create new Releases
-------------------

[](#create-new-releases)

To generate a new release:

First you need to install composer dependencies of desired adapters, as mentioned above, and then, generate the package:

```
composer archive --format=zip --file=dist/sbmailer
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

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

Recently: every ~10 days

Total

14

Last Release

1140d ago

Major Versions

v1.0.1 → 2.0.02022-07-01

2.1.0 → 3.0.02022-08-02

3.2.5 → 4.0.02023-03-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/b713cde13f495bfe7b6b213b7dbe963d0abb0db79103e782f06a69b936dbe2ee?d=identicon)[genilto](/maintainers/genilto)

---

Top Contributors

[![genilto](https://avatars.githubusercontent.com/u/7434575?v=4)](https://github.com/genilto "genilto (74 commits)")

---

Tags

emailadaptersendsbmailer

### Embed Badge

![Health badge](/badges/genilto-sbmailer/health.svg)

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

###  Alternatives

[egulias/email-validator

A library for validating emails against several RFCs

11.6k691.3M307](/packages/egulias-email-validator)[sendgrid/sendgrid

This library allows you to quickly and easily send emails through Twilio SendGrid using PHP.

1.5k47.5M164](/packages/sendgrid-sendgrid)[pelago/emogrifier

Converts CSS styles into inline style attributes in your HTML code

94944.1M110](/packages/pelago-emogrifier)[zbateson/mail-mime-parser

MIME email message parser

53949.2M79](/packages/zbateson-mail-mime-parser)[soundasleep/html2text

A PHP script to convert HTML into a plain text format

48419.5M75](/packages/soundasleep-html2text)[sendgrid/smtpapi

Build SendGrid X-SMTPAPI headers in PHP.

696.5M2](/packages/sendgrid-smtpapi)

PHPackages © 2026

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