{"id":14966355,"url":"https://github.com/yiisoft/yii2-symfonymailer","last_synced_at":"2025-05-16T13:03:38.064Z","repository":{"id":41277541,"uuid":"440594575","full_name":"yiisoft/yii2-symfonymailer","owner":"yiisoft","description":"Yii 2 Symfony mailer extension.","archived":false,"fork":false,"pushed_at":"2024-12-24T11:26:01.000Z","size":118,"stargazers_count":45,"open_issues_count":2,"forks_count":22,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-05-07T06:33:52.434Z","etag":null,"topics":["email","hacktoberfest","mail","mailer","symfony","yii2"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"],"tidelift":"packagist/yiisoft/yii2-symfonymailer"}},"created_at":"2021-12-21T17:12:42.000Z","updated_at":"2025-04-28T20:25:07.000Z","dependencies_parsed_at":"2023-11-30T14:02:42.114Z","dependency_job_id":"3620553a-5a22-40ce-a254-2fca55931574","html_url":"https://github.com/yiisoft/yii2-symfonymailer","commit_stats":{"total_commits":73,"total_committers":17,"mean_commits":4.294117647058823,"dds":0.7123287671232876,"last_synced_commit":"04577a7876c10a188f6a816e5fd087bdeac74ff1"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fyii2-symfonymailer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fyii2-symfonymailer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fyii2-symfonymailer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fyii2-symfonymailer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/yii2-symfonymailer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254453906,"owners_count":22073675,"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":["email","hacktoberfest","mail","mailer","symfony","yii2"],"created_at":"2024-09-24T13:36:15.901Z","updated_at":"2025-05-16T13:03:38.041Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft","https://tidelift.com/funding/github/packagist/yiisoft/yii2-symfonymailer"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii Mailer Library - Symfony Mailer Extension\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\nThis extension provides a [Symfony Mailer](https://symfony.com/doc/5.4/mailer.html) mail solution for [Yii framework 2.0](https://www.yiiframework.com).\n\nFor license information check the [LICENSE](LICENSE.md)-file.\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2-symfonymailer/v/stable.png)](https://packagist.org/packages/yiisoft/yii2-symfonymailer)\n[![Total Downloads](https://poser.pugx.org/yiisoft/yii2-symfonymailer/downloads.png)](https://packagist.org/packages/yiisoft/yii2-symfonymailer)\n[![Build Status](https://github.com/yiisoft/yii2-symfonymailer/workflows/build/badge.svg)](https://github.com/yiisoft/yii2-symfonymailer/actions)\n[![codecov](https://codecov.io/gh/yiisoft/yii2-symfonymailer/graph/badge.svg?token=XCj60xP699)](https://codecov.io/gh/yiisoft/yii2-symfonymailer)\n[![static analysis](https://github.com/yiisoft/yii2-symfonymailer/actions/workflows/static.yml/badge.svg)](https://github.com/yiisoft/yii2-symfonymailer/actions/workflows/static.yml)\n[![type-coverage](https://shepherd.dev/github/yiisoft/yii2-symfonymailer/coverage.svg)](https://shepherd.dev/github/yiisoft/yii2-symfonymailer)\n\nRequirements\n------------\n\n- PHP 8.1 or higher.\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](https://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist yiisoft/yii2-symfonymailer\n```\n\nor add\n\n```json\n\"yiisoft/yii2-symfonymailer\": \"~3.0.0\"\n```\n\nto the require section of your composer.json.\n\nUsage\n-----\n\nTo use this extension,  simply add the following code in your application configuration:\n\n```php\nreturn [\n    //....\n    'components' =\u003e [\n        'mailer' =\u003e [\n            'class' =\u003e \\yii\\symfonymailer\\Mailer::class,            \n            'transport' =\u003e [\n                'scheme' =\u003e 'smtps',\n                'host' =\u003e '',\n                'username' =\u003e '',\n                'password' =\u003e '',\n                'port' =\u003e 465,\n                'dsn' =\u003e 'native://default',\n            ],\n            'viewPath' =\u003e '@common/mail',\n            // send all mails to a file by default. You have to set\n            // 'useFileTransport' to false and configure transport\n            // for the mailer to send real emails.\n            'useFileTransport' =\u003e false,\n        ],\n    ],\n];\n```\nor\n```php\nreturn [\n    //....\n    'components' =\u003e [\n        'mailer' =\u003e [\n            'class' =\u003e \\yii\\symfonymailer\\Mailer::class,            \n            'transport' =\u003e [\n                'dsn' =\u003e 'smtp://user:pass@smtp.example.com:25',\n            ],\n        ],\n    ],\n];\n```\n\nYou can then send an email as follows:\n\n```php\nYii::$app-\u003emailer-\u003ecompose('contact/html')\n     -\u003esetFrom('from@domain.com')\n     -\u003esetTo($form-\u003eemail)\n     -\u003esetSubject($form-\u003esubject)\n     -\u003esend();\n```\n\nDI Container\n------------\nThe `Mailer` component will automatically use the DI container when it is available.\nThis allows you to easily override the transport factory configurations or their dependencies.\n\nMigrating from yiisoft/yii2-swiftmailer\n---------------------------------------\n\nTo migrate from the deprecated [yiisoft/yii2-swiftmailer](https://github.com/yiisoft/yii2-swiftmailer) to this extension you need to update the application config.\n\nSwiftmailer default transport was the `SendmailTransport`, while with this extension it will default to a `NullTransport` (sends no mail). You can use the swiftmailer default like the following:\n\n   ```php\n   'mailer' =\u003e [\n       'class' =\u003e yii\\symfonymailer\\Mailer::class,\n       'transport' =\u003e [\n           'dsn' =\u003e 'sendmail://default',\n       ],\n   ],\n   ```\nWith this extension, you do not have an ability of directly setting timeout, or other configurations that were possible with Swiftmailer extension. The reason is, the underlying Symfony package defines its classes as `final` thereby discouraging inheritance and pushing towards composition. \n\nTo achieve timeout, for example (and other transport configurations supported), you will need to define factory class and override default transport factory you are interested to replace through [Yii DI container](https://www.yiiframework.com/doc/guide/2.0/en/concept-di-container) definitions.\n\nBelow is an example that shows you how to ovveride timeout.\n\nFirst define your custom factory class.\n\n```php\nnamespace app\\utils;\n\nuse Symfony\\Component\\Mailer\\Transport\\Dsn;\nuse Symfony\\Component\\Mailer\\Transport\\Smtp\\SmtpTransport;\nuse Symfony\\Component\\Mailer\\Transport\\TransportFactoryInterface;\nuse Symfony\\Component\\Mailer\\Transport\\TransportInterface;\nuse yii\\base\\BaseObject;\n\nfinal class CustomSmtpFactory extends BaseObject implements TransportFactoryInterface\n{\n    public float $timeout;\n\n    public function create(Dsn $dsn): TransportInterface\n    {\n        $transport = $this-\u003ecreate($dsn);\n        if ($transport instanceof SmtpTransport) {\n\n            /** @var SocketStream $stream */\n            $stream = $transport-\u003egetStream();\n            $stream-\u003esetTimeout($this-\u003etimeout);\n        }\n        return $transport;\n    }\n\n    public function supports(Dsn $dsn): bool\n    {\n        return $dsn-\u003egetScheme() == 'smtp';\n    }\n}\n```\n\nThen in the root of web configuration, set the factory class in container definitions, thereby overriding the default class.\n\n```php\n'container' =\u003e [\n    'definitions' =\u003e [\n        EsmtpTransportFactory::class =\u003e [\n            'class' =\u003e \\app\\utils\\CustomSmtpFactory::class,\n            'timeout' =\u003e 143, //Configure it to your own timeout\n        ],\n        // ... other definitions\n    ],\n],\n  ```\n\nThat is all you need to do. The extension should use your new class and its configuration settings.\n\nSecurity implications of the DSN\n--------------------------------\n\nWhile the DSN might seem like a simple way to allow user configurable mailer settings it should be noted that the sendmail transport allows for execution of local executables.\nIf you need to have a user configurable DSN (which is easier to build and more powerful to use than creating a GUI) you should probably disable the sendmail transport.\nAny user who has the power to configure a DSN essentially has shell access to wherever the code is running.\n\n## Testing\n\n[Check the documentation testing](/docs/testing.md) to learn about testing.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fyii2-symfonymailer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Fyii2-symfonymailer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fyii2-symfonymailer/lists"}