PHPackages                             finesse/swiftmailer-defaults-plugin - 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. finesse/swiftmailer-defaults-plugin

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

finesse/swiftmailer-defaults-plugin
===================================

A plugin for SwiftMailer and Symfony that sets default properties for email Messages (from, sender, reply to and so on)

v2.0.3(8y ago)7104.7k↓63.9%5MITPHPPHP &gt;=5.6CI failing

Since Oct 8Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Finesse/SwiftMailerDefaultsPlugin)[ Packagist](https://packagist.org/packages/finesse/swiftmailer-defaults-plugin)[ Docs](https://github.com/FinesseRus/SwiftMailerDefaultsPlugin)[ RSS](/packages/finesse-swiftmailer-defaults-plugin/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (4)Dependencies (3)Versions (6)Used By (0)

[Swift Mailer](https://swiftmailer.symfony.com/) Defaults Plugin
================================================================

[](#swift-mailer-defaults-plugin)

[![Latest Stable Version](https://camo.githubusercontent.com/cbdfea60392e3231639e3daa2741c8de2253493b2786fe65e790662ce43b3aee/68747470733a2f2f706f7365722e707567782e6f72672f66696e657373652f73776966746d61696c65722d64656661756c74732d706c7567696e2f762f737461626c65)](https://packagist.org/packages/finesse/swiftmailer-defaults-plugin)[![Total Downloads](https://camo.githubusercontent.com/df6def0d4ce7ff6ad3358018f085e7a13218fd4633e39fa6fb99c647993ff9ed/68747470733a2f2f706f7365722e707567782e6f72672f66696e657373652f73776966746d61696c65722d64656661756c74732d706c7567696e2f646f776e6c6f616473)](https://packagist.org/packages/finesse/swiftmailer-defaults-plugin)[![PHP from Packagist](https://camo.githubusercontent.com/f71b3f92ec46d9643a8ccd07bf94f0f62606da4b569a4519aa0e42e99c2c95a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f66696e657373652f73776966746d61696c65722d64656661756c74732d706c7567696e2e737667)](https://camo.githubusercontent.com/f71b3f92ec46d9643a8ccd07bf94f0f62606da4b569a4519aa0e42e99c2c95a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f66696e657373652f73776966746d61696c65722d64656661756c74732d706c7567696e2e737667)[![Test Status](https://github.com/finesse/SwiftMailerDefaultsPlugin/workflows/Test/badge.svg)](https://github.com/Finesse/SwiftMailerDefaultsPlugin/actions?workflow=Test)[![Maintainability](https://camo.githubusercontent.com/af7bd6a8831c3e3915ff8d2386635fa9cb7302061011cdea127a7d81be64b9bb/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f39356637383733633561393165323439343334352f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Finesse/SwiftMailerDefaultsPlugin/maintainability)[![Test Coverage](https://camo.githubusercontent.com/81b2b5e2f2825c5d95d26cd84d3c1abd67011e8ecc07c998b6e6b057948c2e22/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f39356637383733633561393165323439343334352f746573745f636f766572616765)](https://codeclimate.com/github/Finesse/SwiftMailerDefaultsPlugin/test_coverage)

This plugin adds a possibility to set default properties for the sent Messages (default from address, reply to, subject and so on).

```
// Set up a Mailer
$transport = new Swift_SmtpTransport();
$mailer = new Swift_Mailer($transport);
$mailer->registerPlugin(new Finesse\SwiftMailerDefaultsPlugin\SwiftMailerDefaultsPlugin([
    'from' => ['johndoe@example.com' => 'John Doe'],
    'replyTo' => 'jackdoe@example.com'
]));

// Use the Mailer many times
$mailer->send(
    (new Swift_Message())
        ->setTo('bjohnson@example.com', 'Bill Johnson')
        ->setSubject('Hi')
        ->setBody('This is awesome, I don\'t need to specify the from address!')
);
```

How to install
--------------

[](#how-to-install)

### Using [composer](https://getcomposer.org)

[](#using-composer)

Run in a console

```
composer require finesse/swiftmailer-defaults-plugin
```

How to use
----------

[](#how-to-use)

Create and register a plugin instance when you setup a `Swift_Mailer` instance.

```
use Finesse\SwiftMailerDefaultsPlugin\SwiftMailerDefaultsPlugin;
use Swift_Mailer;
use Swift_SmtpTransport;

// Setup an emails sending transport
$transport = new Swift_SmtpTransport();

// Create a plugin instance
$defaultsPlugin = new SwiftMailerDefaultsPlugin(/* default properties */);

// Assemble them with a mailer
$mailer = new Swift_Mailer($transport);
$mailer->registerPlugin($defaultsPlugin);
```

For [Symfony](https://github.com/symfony/swiftmailer-bundle) 4 you can register the plugin this way:

```
services:
    # Swift Mailer plugins
    Finesse\SwiftMailerDefaultsPlugin\SwiftMailerDefaultsPlugin:
        tags:
              - { name: swiftmailer.default.plugin }
        arguments:
              $defaults:
                  from:
                      johndoe@example.com: John Doe
                  replyTo: jackdoe@example.com

```

Symfony 3 example```
services:
    # Swift Mailer plugins
    app.swiftmailer.defaults_plugin:
        class: Finesse\SwiftMailerDefaultsPlugin\SwiftMailerDefaultsPlugin
        tags:
              - { name: swiftmailer.default.plugin }
        arguments:
              $defaults:
                  from:
                      johndoe@example.com: John Doe
                  replyTo: jackdoe@example.com

```

When you need to send an email, just send it without specifying the parameters you set to the plugin instance.

```
use Swift_Message;

$message = new Swift_Message();
$mailer->send($message);
```

If you specify, the specified parameters will override the default properties.

### \_\_constructor

[](#__constructor)

You can pass to the constructor all the properties that you can set to a `Swift_Mime_SimpleMessage` instance using the `set...` methods. For example:

```
$defaultsPlugin = new SwiftMailerDefaultsPlugin([
    'from' => 'johndoe@example.com',
    'subject' => 'Notification'
]);
```

The array keys are the names of the properties that are the `Swift_Mime_SimpleMessage` methods names without the `set`word and with the lowercase first letter. For example, the `body` property corresponds to the `setBody` method, `readReceiptTo` to `setReadReceiptTo` and so on.

The array values are the first and the only arguments for the corresponding methods. Properties with the `null` value are ignored.

### setDefault

[](#setdefault)

Sets a default value for a property.

```
$defaultsPlugin->setDefault('sender', 'chasy@example.com', 'Chasy');
```

The first argument is the property name (see [\_\_constructor](#__constructor) for reference). The rest arguments are the corresponding method arguments.

### unsetDefault

[](#unsetdefault)

Removes a default value

```
$defaultsPlugin->unsetDefault('sender');
```

The only argument is the property name (see [\_\_constructor](#__constructor) for reference).

Versions compatibility
----------------------

[](#versions-compatibility)

The project follows the [Semantic Versioning](http://semver.org).

License
-------

[](#license)

MIT. See [the LICENSE](LICENSE) file for details.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

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

Total

5

Last Release

2986d ago

Major Versions

v1.0 → v2.02017-10-20

PHP version history (2 changes)v1.0PHP &gt;=7.0

v2.0.3PHP &gt;=5.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9006227?v=4)[Sergey M.](/maintainers/Finesse)[@Finesse](https://github.com/Finesse)

---

Top Contributors

[![Finesse](https://avatars.githubusercontent.com/u/9006227?v=4)](https://github.com/Finesse "Finesse (54 commits)")

---

Tags

defaultslibrarypluginswiftmailersymfonypluginsymfonyswiftmailerdefaults

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/finesse-swiftmailer-defaults-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/finesse-swiftmailer-defaults-plugin/health.svg)](https://phpackages.com/packages/finesse-swiftmailer-defaults-plugin)
```

###  Alternatives

[railsware/mailtrap-php

The Mailtrap SDK provides methods for all API functions.

60929.1k](/packages/railsware-mailtrap-php)[cspoo/swiftmailer-mailgun-bundle

Swiftmailer Mailgun bundle

1061.1M](/packages/cspoo-swiftmailer-mailgun-bundle)

PHPackages © 2026

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