{"id":16294738,"url":"https://github.com/finesse/swiftmailerdefaultsplugin","last_synced_at":"2026-03-06T16:34:06.411Z","repository":{"id":62504788,"uuid":"106073003","full_name":"Finesse/SwiftMailerDefaultsPlugin","owner":"Finesse","description":"A plugin for SwiftMailer and Symfony that sets default properties for email Messages","archived":false,"fork":false,"pushed_at":"2020-02-01T05:15:39.000Z","size":35,"stargazers_count":7,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-10T10:05:13.130Z","etag":null,"topics":["defaults","library","plugin","swiftmailer","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Finesse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["Finesse"],"patreon":"surgiefinesse","custom":"http://money.yandex.ru/to/410012160248971"}},"created_at":"2017-10-07T05:09:42.000Z","updated_at":"2021-09-28T06:45:36.000Z","dependencies_parsed_at":"2022-11-02T12:45:27.039Z","dependency_job_id":null,"html_url":"https://github.com/Finesse/SwiftMailerDefaultsPlugin","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finesse%2FSwiftMailerDefaultsPlugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finesse%2FSwiftMailerDefaultsPlugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finesse%2FSwiftMailerDefaultsPlugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finesse%2FSwiftMailerDefaultsPlugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Finesse","download_url":"https://codeload.github.com/Finesse/SwiftMailerDefaultsPlugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244047647,"owners_count":20389206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["defaults","library","plugin","swiftmailer","symfony"],"created_at":"2024-10-10T20:16:19.754Z","updated_at":"2026-03-06T16:34:01.354Z","avatar_url":"https://github.com/Finesse.png","language":"PHP","funding_links":["https://github.com/sponsors/Finesse","https://patreon.com/surgiefinesse","http://money.yandex.ru/to/410012160248971"],"categories":[],"sub_categories":[],"readme":"# [Swift Mailer](https://swiftmailer.symfony.com/) Defaults Plugin\n\n[![Latest Stable Version](https://poser.pugx.org/finesse/swiftmailer-defaults-plugin/v/stable)](https://packagist.org/packages/finesse/swiftmailer-defaults-plugin)\n[![Total Downloads](https://poser.pugx.org/finesse/swiftmailer-defaults-plugin/downloads)](https://packagist.org/packages/finesse/swiftmailer-defaults-plugin)\n![PHP from Packagist](https://img.shields.io/packagist/php-v/finesse/swiftmailer-defaults-plugin.svg)\n[![Test Status](https://github.com/finesse/SwiftMailerDefaultsPlugin/workflows/Test/badge.svg)](https://github.com/Finesse/SwiftMailerDefaultsPlugin/actions?workflow=Test)\n[![Maintainability](https://api.codeclimate.com/v1/badges/95f7873c5a91e2494345/maintainability)](https://codeclimate.com/github/Finesse/SwiftMailerDefaultsPlugin/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/95f7873c5a91e2494345/test_coverage)](https://codeclimate.com/github/Finesse/SwiftMailerDefaultsPlugin/test_coverage)\n\nThis plugin adds a possibility to set default properties for the sent Messages \n(default from address, reply to, subject and so on).\n\n```php\n// Set up a Mailer\n$transport = new Swift_SmtpTransport();\n$mailer = new Swift_Mailer($transport);\n$mailer-\u003eregisterPlugin(new Finesse\\SwiftMailerDefaultsPlugin\\SwiftMailerDefaultsPlugin([\n    'from' =\u003e ['johndoe@example.com' =\u003e 'John Doe'],\n    'replyTo' =\u003e 'jackdoe@example.com'\n]));\n\n// Use the Mailer many times\n$mailer-\u003esend(\n    (new Swift_Message())\n        -\u003esetTo('bjohnson@example.com', 'Bill Johnson')\n        -\u003esetSubject('Hi')\n        -\u003esetBody('This is awesome, I don\\'t need to specify the from address!')\n);\n```\n\n\n## How to install\n\n### Using [composer](https://getcomposer.org)\n\nRun in a console\n\n```bash\ncomposer require finesse/swiftmailer-defaults-plugin\n```\n\n\n## How to use\n\nCreate and register a plugin instance when you setup a `Swift_Mailer` instance.\n\n```php\nuse Finesse\\SwiftMailerDefaultsPlugin\\SwiftMailerDefaultsPlugin;\nuse Swift_Mailer;\nuse Swift_SmtpTransport;\n\n// Setup an emails sending transport\n$transport = new Swift_SmtpTransport();\n\n// Create a plugin instance\n$defaultsPlugin = new SwiftMailerDefaultsPlugin(/* default properties */);\n\n// Assemble them with a mailer\n$mailer = new Swift_Mailer($transport);\n$mailer-\u003eregisterPlugin($defaultsPlugin);\n```\n\nFor [Symfony](https://github.com/symfony/swiftmailer-bundle) 4 you can register the plugin this way:\n\n```yaml\nservices:\n    # Swift Mailer plugins\n    Finesse\\SwiftMailerDefaultsPlugin\\SwiftMailerDefaultsPlugin:\n        tags:\n              - { name: swiftmailer.default.plugin }\n        arguments:\n              $defaults:\n                  from:\n                      johndoe@example.com: John Doe\n                  replyTo: jackdoe@example.com\n     \n```\n\n\u003cdetails\u003e\n\u003csummary\u003eSymfony 3 example\u003c/summary\u003e\n    \n```yaml\nservices:\n    # Swift Mailer plugins\n    app.swiftmailer.defaults_plugin:\n        class: Finesse\\SwiftMailerDefaultsPlugin\\SwiftMailerDefaultsPlugin\n        tags:\n              - { name: swiftmailer.default.plugin }\n        arguments:\n              $defaults:\n                  from:\n                      johndoe@example.com: John Doe\n                  replyTo: jackdoe@example.com\n     \n```\n\n\u003c/details\u003e\n\nWhen you need to send an email, just send it without specifying the parameters you set to the plugin instance.\n\n```php\nuse Swift_Message;\n\n$message = new Swift_Message();\n$mailer-\u003esend($message);\n```\n\nIf you specify, the specified parameters will override the default properties.\n\n### __constructor\n\nYou can pass to the constructor all the properties that you can set to a `Swift_Mime_SimpleMessage` instance using the \n`set...` methods. For example:\n\n```php\n$defaultsPlugin = new SwiftMailerDefaultsPlugin([\n    'from' =\u003e 'johndoe@example.com',\n    'subject' =\u003e 'Notification'\n]);\n```\n\nThe array keys are the names of the properties that are the `Swift_Mime_SimpleMessage` methods names without the `set` \nword and with the lowercase first letter. For example, the `body` property corresponds to the `setBody` method, \n`readReceiptTo` to `setReadReceiptTo` and so on.\n\nThe array values are the first and the only arguments for the corresponding methods. Properties with the `null` value \nare ignored.\n\n### setDefault\n\nSets a default value for a property.\n\n```php\n$defaultsPlugin-\u003esetDefault('sender', 'chasy@example.com', 'Chasy');\n```\n\nThe first argument is the property name (see [__constructor](#__constructor) for reference). The rest arguments are the \ncorresponding method arguments.\n\n### unsetDefault\n\nRemoves a default value\n\n```php\n$defaultsPlugin-\u003eunsetDefault('sender');\n```\n\nThe only argument is the property name (see [__constructor](#__constructor) for reference).\n\n\n## Versions compatibility\n\nThe project follows the [Semantic Versioning](http://semver.org).\n\n\n## License\n\nMIT. See [the LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinesse%2Fswiftmailerdefaultsplugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffinesse%2Fswiftmailerdefaultsplugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinesse%2Fswiftmailerdefaultsplugin/lists"}