{"id":18750685,"url":"https://github.com/webiny/mailer","last_synced_at":"2025-11-26T21:30:14.631Z","repository":{"id":20228017,"uuid":"23499871","full_name":"webiny/Mailer","owner":"webiny","description":"[READ-ONLY]  The `Mailer` is a PHP component that enables you to send emails using different supported protocols and functions (SMTP, mail(), sendmail).  (master at Webiny/Framework)","archived":false,"fork":false,"pushed_at":"2017-11-26T21:24:57.000Z","size":42,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-12-28T22:54:15.597Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.webiny.com/","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"barryvdh/laravel-ide-helper","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webiny.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-30T20:14:22.000Z","updated_at":"2023-05-21T17:38:19.000Z","dependencies_parsed_at":"2022-08-22T15:40:26.030Z","dependency_job_id":null,"html_url":"https://github.com/webiny/Mailer","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FMailer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FMailer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FMailer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FMailer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webiny","download_url":"https://codeload.github.com/webiny/Mailer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239636229,"owners_count":19672307,"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":[],"created_at":"2024-11-07T17:12:49.494Z","updated_at":"2025-11-26T21:30:14.566Z","avatar_url":"https://github.com/webiny.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Mailer Component\n================\n\nThe `Mailer` component enables you to send emails using different supported protocols.\n\nInstall the component\n---------------------\nThe best way to install the component is using Composer.\n\n```bash\ncomposer require webiny/mailer\n```\nFor additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/mailer).\n\n## Usage\n\nCurrent supported protocols are:\n\n* SMTP (you can also use Mandrill and Sendgrid's via their SMTP API)\n* PHPs' `mail()` function\n* Sendmail\n* Mandrill ([Mandrill API Docs](https://mandrillapp.com/api/docs/messages.php.html#method=send))\n* Sendgrid ([Sendgrid API Docs](https://sendgrid.com/docs/API_Reference/Web_API/mail.html))\n\nTo use the component, you first need to configuration set inside the component config file.\nIf you open the `ExampleConfig.yaml` you can see two example configuration sets, `Demo` and `Gmail`.\nFollow this example to create your own set.\n\nHere is an example configuration:\n\n```yaml\n    Mailer:\n        Default:\n            CharacterSet: utf-8\n            MaxLineLength: 78\n            Priority: 2\n            Sender:\n                Email: nikola@tesla.com\n                Name: Nikola Tesla\n            Transport:\n                Type: smtp\n                Host: smtp.gmail.com\n                Port: 465\n                Username: me@gmail.com\n                Password: ***\n                Encryption: ssl\n                AuthMode: login\n            AntiFlood:\n                Threshold: 99\n                Sleep: 1\n            DisableDelivery: false\n        Mandrill:\n            Mode: template # template or html\n            ApiKey: yourApiKey\n            DisableDelivery: false\n            Message:    # these are all optional\n                FromEmail: ''\n                FromName: ''\n                Headers: []\n                Important: false\n                TrackOpens: null\n                TrackClicks: null\n                AutoText: null\n                AutoHtml: null\n                InlineCss: null\n                UrlStripQs: null\n                PreserveRecipients: null\n                ViewContentLink: null\n                BccAddress: ''\n                TrackingDomain: null\n                SigningDomain: null\n                ReturnPathDomain: null\n                Merge: true\n                MergeLanguage: mailchimp\n                Tags: []\n                Subaccount: null\n                GoogleAnalyticsDomains: []\n                GoogleAnalyticsCampaign: ''\n                Metadata: []\n                RecipientMetadata: []\n                Attachments: []\n        Sendgrid:\n            ApiUser: yourApiUser\n            ApiKey: yourApiKey\n            DisableDelivery: false\n            Decorators:\n                Wrapper: ['*|', '|*']\n```\n\nYou can have unlimited configuration sets.\n\nTo register the config with the component, just call `Mailer::setConfig($pathToYamlConfig)`.\n\nDepending on defined `Transport.Type` other transport parameters are required.\n\n## Configuration parameters\n\nThe `Mailer` configuration consists of several parameters that are explained in the next few sections.\n\n**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.\n\n### Character set (`CharacterSet`)\n\nThis is the default character set that will be used in encoding your email content.\nBy default the character set is set to `utf-8` which supports most language characters.\nYou might need to change this for some languages, for example, like Japanese.\n\n### Sender (`Sender`)\n\nThis is the default sender that will be set on your outgoing emails.\n\n### Transport (`Transport`)\n\nThe transport configuration block consists of following parameters: \n\n- `Type`\n    - defines the type of the connection\n    - can be `smtp`, `mail` or `sendmail`\n\n\nThese parameters are needed only in case of a SMTP connection:\n\n- `Host`\n    - defines the location of your smtp host\n- `Port`\n-   - the port used to connect to the host\n    - port can vary based on the defined `encryption` and `auth_mode`  \n- `Username`\n    - username needed to connect to the host\n- `Password`\n    - password needed to connect to the host\n- `Encryption`\n    - encryption used for the connection\n    - this parameter is optional\n    - can be `ssl` or `tls` based on your host\n- `AuthMode`\n    - authorization mode used to connect to the host\n    - this parameter is optional\n    - can be `plain`, `login`, `cram-md5`, or `null`\n\n### AntiFlood (`AntiFood`)\n\nSome 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.\n\nDon'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.\n\nThe `AntiFood` param consists of two attributes:\n- `Threshold`\n    - defines how many emails to send per one connection\n- `Sleep`\n    - defines how many seconds to wait until a new connection can be established and the sending resumed\n\n\n## Usage\n\nUsing the `Mailer` component is quite simple, just implement the `MailerTrait`, build your message and send it.\n\nHere is one simple usage example:\n\n```php\nclass MyClass\n{\n    use \\Webiny\\Component\\Mailer\\Bridge\\MailerTrait;\n\n\tfunction sendEmail() {\n\t\t// get the Mailer instance\n\t\t$mailer = $this-\u003emailer('Default');\n\n\t\t// let's build our message\n\t\t$msg = $mailer-\u003egetMessage();\n\t\t$msg-\u003esetSubject('Hello email')\n\t\t\t-\u003esetBody('This is my test email body')\n\t\t\t-\u003esetTo(new Email('me@gmail.com', 'Jack'));\n\n\t\t// send it\n\t\t$mailer-\u003esend($msg);\n\t}\n}\n```\n\nNow 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,\nfor example that in each email you put the name of the specific user.\n\n```php\nclass MyClass\n{\n\tuse \\Webiny\\Component\\Mailer\\Bridge\\MailerTrait;\n\n\tfunction sendEmail() {\n\t\t// get the Mailer instance\n\t\t$mailer = $this-\u003emailer('Default');\n\n\n\t\t// let's build our message\n\t\t$msg = $mailer-\u003egetMessage();\n\t\t$msg-\u003esetSubject('Hello email')\n\t\t\t -\u003esetBody('Hi {name},\n\t\t\t\t\t\t   This is your new password: \u003cstrong\u003e{password}\u003c/strong\u003e.')\n\t\t\t -\u003esetTo([\n\t\t\t\t\tnew Email('jack@gmail.com'),\n\t\t\t\t\tnew Email('sara@gmail.com')\n\t\t\t\t\t]);\n\n\t\t// before sending, let's define the decorator replacements\n\t\t$replacements = [\n\t\t\t'jack@gmail.com' =\u003e [\n\t\t\t\t'name'     =\u003e 'Jack',\n\t\t\t\t'password' =\u003e 'seCre!'\n\t\t\t],\n\n\t\t\t'sara@gmail.com' =\u003e [\n\t\t\t\t'name'     =\u003e 'Sara',\n\t\t\t\t'password' =\u003e 'Log!n'\n\t\t\t]\n\t\t];\n\t\t$mailer-\u003esetDecorators($replacements);\n\n\t\t// send it\n\t\t$mailer-\u003esend($msg);\n\t}\n}\n```\n\n## Bridge\n\nThe default bridge library is `SwiftMailer` (http://swiftmailer.org/).\n\nIf you wish to create your own driver ,you need to create three classes:\n\n- **Message**\n    - this class should implement `\\Webiny\\Component\\Mailer\\Bridge\\MessageInterface`\n    - this class is used for populating message attributes, like sender, body ...\n- **Transport**\n    - this class should implement `\\Webiny\\Component\\Mailer\\Bridge\\TransportInterface`\n    - it is used for sending the message\n- **Mailer**\n    - this class should implement `\\Webiny\\Component\\Mailer\\Bridge\\MailerInterface`\n    - this class has only two methods, one returns an instance of Message and the other an instance of Transport\n\nResources\n---------\n\nTo run unit tests, you need to use the following command:\n\n    $ cd path/to/Webiny/Component/Mailer/\n    $ composer.phar install\n    $ phpunit","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fmailer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebiny%2Fmailer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fmailer/lists"}