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

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

webiny/mailer
=============

Webiny Mail Component

v1.6.1(8y ago)241MITPHPPHP ^7

Since Sep 20Pushed 8y ago8 watchersCompare

[ Source](https://github.com/Webiny/Mailer)[ Packagist](https://packagist.org/packages/webiny/mailer)[ Docs](http://www.webiny.com/)[ RSS](/packages/webiny-mailer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (23)Used By (0)

Mailer Component
================

[](#mailer-component)

The `Mailer` component enables you to send emails using different supported protocols.

Install the component
---------------------

[](#install-the-component)

The best way to install the component is using Composer.

```
composer require webiny/mailer
```

For additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/mailer).

Usage
-----

[](#usage)

Current supported protocols are:

- SMTP (you can also use Mandrill and Sendgrid's via their SMTP API)
- PHPs' `mail()` function
- Sendmail
- Mandrill ([Mandrill API Docs](https://mandrillapp.com/api/docs/messages.php.html#method=send))
- Sendgrid ([Sendgrid API Docs](https://sendgrid.com/docs/API_Reference/Web_API/mail.html))

To use the component, you first need to configuration set inside the component config file. If you open the `ExampleConfig.yaml` you can see two example configuration sets, `Demo` and `Gmail`. Follow this example to create your own set.

Here is an example configuration:

```
    Mailer:
        Default:
            CharacterSet: utf-8
            MaxLineLength: 78
            Priority: 2
            Sender:
                Email: nikola@tesla.com
                Name: Nikola Tesla
            Transport:
                Type: smtp
                Host: smtp.gmail.com
                Port: 465
                Username: me@gmail.com
                Password: ***
                Encryption: ssl
                AuthMode: login
            AntiFlood:
                Threshold: 99
                Sleep: 1
            DisableDelivery: false
        Mandrill:
            Mode: template # template or html
            ApiKey: yourApiKey
            DisableDelivery: false
            Message:    # these are all optional
                FromEmail: ''
                FromName: ''
                Headers: []
                Important: false
                TrackOpens: null
                TrackClicks: null
                AutoText: null
                AutoHtml: null
                InlineCss: null
                UrlStripQs: null
                PreserveRecipients: null
                ViewContentLink: null
                BccAddress: ''
                TrackingDomain: null
                SigningDomain: null
                ReturnPathDomain: null
                Merge: true
                MergeLanguage: mailchimp
                Tags: []
                Subaccount: null
                GoogleAnalyticsDomains: []
                GoogleAnalyticsCampaign: ''
                Metadata: []
                RecipientMetadata: []
                Attachments: []
        Sendgrid:
            ApiUser: yourApiUser
            ApiKey: yourApiKey
            DisableDelivery: false
            Decorators:
                Wrapper: ['*|', '|*']
```

You can have unlimited configuration sets.

To register the config with the component, just call `Mailer::setConfig($pathToYamlConfig)`.

Depending on defined `Transport.Type` other transport parameters are required.

Configuration parameters
------------------------

[](#configuration-parameters)

The `Mailer` configuration consists of several parameters that are explained in the next few sections.

**Note:** Some of the configuration parameters are bridge-specific, like the `AntiFlood` parameter. The default bridge is the **SwiftMailer**, which of course supports the AntiFlood measures.

### Character set (`CharacterSet`)

[](#character-set-characterset)

This is the default character set that will be used in encoding your email content. By default the character set is set to `utf-8` which supports most language characters. You might need to change this for some languages, for example, like Japanese.

### Sender (`Sender`)

[](#sender-sender)

This is the default sender that will be set on your outgoing emails.

### Transport (`Transport`)

[](#transport-transport)

The transport configuration block consists of following parameters:

- `Type`
    - defines the type of the connection
    - can be `smtp`, `mail` or `sendmail`

These parameters are needed only in case of a SMTP connection:

- `Host`
    - defines the location of your smtp host
- `Port`
- - the port used to connect to the host
    - port can vary based on the defined `encryption` and `auth_mode`
- `Username`
    - username needed to connect to the host
- `Password`
    - password needed to connect to the host
- `Encryption`
    - encryption used for the connection
    - this parameter is optional
    - can be `ssl` or `tls` based on your host
- `AuthMode`
    - authorization mode used to connect to the host
    - this parameter is optional
    - can be `plain`, `login`, `cram-md5`, or `null`

### AntiFlood (`AntiFood`)

[](#antiflood-antifood)

Some mail servers have a set of safety measures that limit the amout of emails that you can send per connection or in some time interval. This is mostly to discourage spammers to user their services, but sometimes that might cause a problem even for non-spammers. In order to avoid falling into these safety measure the `AntiFood` parameter can limit how many emails you can send per connection and how much time you have to wait until you can establishe a new connection.

Don't worry about disconnecting, connecting again and resuming the sending of emails...this is all fully authomized and you don't have to do anything.

The `AntiFood` param consists of two attributes:

- `Threshold`
    - defines how many emails to send per one connection
- `Sleep`
    - defines how many seconds to wait until a new connection can be established and the sending resumed

Usage
-----

[](#usage-1)

Using the `Mailer` component is quite simple, just implement the `MailerTrait`, build your message and send it.

Here is one simple usage example:

```
class MyClass
{
    use \Webiny\Component\Mailer\Bridge\MailerTrait;

	function sendEmail() {
		// get the Mailer instance
		$mailer = $this->mailer('Default');

		// let's build our message
		$msg = $mailer->getMessage();
		$msg->setSubject('Hello email')
			->setBody('This is my test email body')
			->setTo(new Email('me@gmail.com', 'Jack'));

		// send it
		$mailer->send($msg);
	}
}
```

Now if you have multiple senders, and let's say you want to send all of them the same email, but just with a little difference, for example that in each email you put the name of the specific user.

```
class MyClass
{
	use \Webiny\Component\Mailer\Bridge\MailerTrait;

	function sendEmail() {
		// get the Mailer instance
		$mailer = $this->mailer('Default');

		// let's build our message
		$msg = $mailer->getMessage();
		$msg->setSubject('Hello email')
			 ->setBody('Hi {name},
						   This is your new password: {password}.')
			 ->setTo([
					new Email('jack@gmail.com'),
					new Email('sara@gmail.com')
					]);

		// before sending, let's define the decorator replacements
		$replacements = [
			'jack@gmail.com' => [
				'name'     => 'Jack',
				'password' => 'seCre!'
			],

			'sara@gmail.com' => [
				'name'     => 'Sara',
				'password' => 'Log!n'
			]
		];
		$mailer->setDecorators($replacements);

		// send it
		$mailer->send($msg);
	}
}
```

Bridge
------

[](#bridge)

The default bridge library is `SwiftMailer` ().

If you wish to create your own driver ,you need to create three classes:

- **Message**
    - this class should implement `\Webiny\Component\Mailer\Bridge\MessageInterface`
    - this class is used for populating message attributes, like sender, body ...
- **Transport**
    - this class should implement `\Webiny\Component\Mailer\Bridge\TransportInterface`
    - it is used for sending the message
- **Mailer**
    - this class should implement `\Webiny\Component\Mailer\Bridge\MailerInterface`
    - this class has only two methods, one returns an instance of Message and the other an instance of Transport

Resources
---------

[](#resources)

To run unit tests, you need to use the following command:

```
$ cd path/to/Webiny/Component/Mailer/
$ composer.phar install
$ phpunit

```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity73

Established project with proven stability

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

Recently: every ~5 days

Total

22

Last Release

3153d ago

PHP version history (3 changes)v1.0.0PHP &gt;=5.4.0

v1.2.1PHP &gt;=5.5.9

1.5.x-devPHP ^7

### Community

Maintainers

![](https://www.gravatar.com/avatar/4440afa738ed146b05c06073a90345e0464c4f4d042b039532d881ca24859d77?d=identicon)[SvenAlHamad](/maintainers/SvenAlHamad)

---

Top Contributors

[![SvenAlHamad](https://avatars.githubusercontent.com/u/3808420?v=4)](https://github.com/SvenAlHamad "SvenAlHamad (24 commits)")

---

Tags

mailemailmandrillsendmailswiftsend gridemail attachment

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webiny-mailer/health.svg)

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

###  Alternatives

[slm/mail

Integration of various email service providers in the Laminas\\Mail

108732.4k1](/packages/slm-mail)[omnimail/omnimail

PHP Library to send email across all platforms using one interface.

32934.3k](/packages/omnimail-omnimail)[slot/mandrill-bundle

Symfony Mandrill Bundle

671.5M1](/packages/slot-mandrill-bundle)[swissup/module-email

Magento2 email providers integration (smtp, mandrill, amazon ses)

1412.8k1](/packages/swissup-module-email)[goetas/to-swift-mime-parser

Parse a generic mail stream, and convert it to a SwiftMailer Message

1244.4k2](/packages/goetas-to-swift-mime-parser)

PHPackages © 2026

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