{"id":21890921,"url":"https://github.com/statikbe/laravel-mail-template-engine","last_synced_at":"2025-04-15T13:39:50.160Z","repository":{"id":57059239,"uuid":"373530661","full_name":"statikbe/laravel-mail-template-engine","owner":"statikbe","description":"Customizable (database) mail templates for Laravel","archived":false,"fork":false,"pushed_at":"2023-06-15T07:38:53.000Z","size":58,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2024-09-21T12:24:30.269Z","etag":null,"topics":["laravel"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/statikbe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-03T14:11:18.000Z","updated_at":"2021-11-23T09:42:47.000Z","dependencies_parsed_at":"2024-11-28T12:18:21.071Z","dependency_job_id":"3d7026dc-c8e7-4919-852c-87e0093a0ec6","html_url":"https://github.com/statikbe/laravel-mail-template-engine","commit_stats":{"total_commits":17,"total_committers":3,"mean_commits":5.666666666666667,"dds":"0.11764705882352944","last_synced_commit":"c921f6ad5d7a31f5e92a49292daeddd9ed127be5"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statikbe%2Flaravel-mail-template-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statikbe%2Flaravel-mail-template-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statikbe%2Flaravel-mail-template-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statikbe%2Flaravel-mail-template-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statikbe","download_url":"https://codeload.github.com/statikbe/laravel-mail-template-engine/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249081516,"owners_count":21209712,"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":["laravel"],"created_at":"2024-11-28T12:18:17.809Z","updated_at":"2025-04-15T13:39:50.140Z","avatar_url":"https://github.com/statikbe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Mail Template Engine\n\nThe Laravel Mail Template Engine makes it possible to create mail templates for your transactional mails. \nThese mail templates can hold content and recipient variables which can be filled when triggering the mail. \n\nThis package works together with our [Laravel Nova Mail Editor](https://github.com/statikbe/laravel-nova-mail-editor) that provides a UI to let content managers edit translations.\n\n## How it works\nThe packages combines 3 different sets of data to send a transactional mail. \n1. Firstly there is the Mail class: here you define a name, content variables and recipient variables.\n2. Next up you store your mail templates in your database, you can do this in Nova using [Laravel Nova Mail Editor](https://github.com/statikbe/laravel-nova-mail-editor). Or you write your own interface to save the templates.\n3. Finally, you call the mail class and fill in its variables (content and recipient). \nAt this moment the engine will look for all templates using this class, starts filling them with the provided variables and send them to the selected recipients.\n \n## Installation\n\n1. Install using composer:\n```\ncomposer require statikbe/laravel-mail-template-engine\n```\n\n2. Publish the mail template migration and config\n```\nphp artisan vendor:publish --tag=mail-template-engine\n```\n\n3. Run the mail template migration\n```\nphp artisan migrate\n```\n\n## How to use\n\n### The mail class\nThis class will decide what content variables are available in your mail template and will be used to decide when a mail is send. \n\nYou can generate a mail with the following command \n```shell script\nphp artisan make:mail-class SomeEventMail\n```\n\nAfter creating a Mail class, add them to the config `mail-template-engine.php` mails.\n\nAn example of a Mail class can be found at `src/Mails/ResetPassword.php`.\n```php\n\u003c?php\n\nnamespace Statikbe\\LaravelMailEditor\\Mails;\n\nuse Statikbe\\LaravelMailEditor\\AbstractMail;\n\nclass ResetPasswordMail extends AbstractMail\n{\n    public static function name(){\n        return __('ResetPasswordTemplate');\n    }\n\n    public static function getContentVariables(){\n        return [\n            'url' =\u003e __('Reset password URL'),\n        ];\n    }\n\n    public static function getRecipientVariables(){\n        return [\n            'user' =\u003e __('User'),\n        ];\n    }\n}\n```\n\n### The Mail Templates\nMail templates are stored in the database. This uses the model `Statikbe\\LaravelMailEditor\\MailTemplate` and can be created like any other model. \nA mail template can be localized, we use Spatie's translatable package for this to work. More information can be found on their page: [Laravel Translatable](https://github.com/spatie/laravel-translatable).\n\nYou can use the keys from your corresponding mail_class to place variable data inside the mail template. \n\nThe `MailTemplate` model consists off:\n\n| Name        | Type   | Description | Example\n| ----------- | ------ | ------------- | -------\n| mail_class  | string | A mail class from config `mail-template-engine.mails` | verify-email\n| name        | string | Just a descriptive naming of the mail for an index page | Email verification mail\n| subject     | json (translatable) | The subject, fillable with `ContentVariables` from the corresponding Mail Class | {\"en\": \"Welcome [[name]], please verify your email\"}\n| body        | json (translatable) | The body, fillable with `ContentVariables` from the corresponding Mail Class | {\"en\": \"Welcome [[name]], please verify your email using the following url [[url]].\"}\n| sender_name | json (translatable) | The sender by name | {\"en\": \"Statik\"}\n| sender_email | json (translatable) | The sender by email | {\"en\": \"info@statik.be\"}\n| recipients | json | The recipients of the mail, an array filled with both `RecipientVariables` from the Mail Class and/or plain emails | [\"user\",\"general@email.com\"]\n| cc | json | The cc of the mail, an array filled with both `RecipientVariables` from the Mail Class and/or plain emails | [\"user\",\"general@email.com\"]\n| bcc | json | The bcc of the mail, an array filled with both `RecipientVariables` from the Mail Class and/or plain emails | [\"user\",\"general@email.com\"]\n| attachments | json (translatable) | work in progress | \n| design | string | A design from config `mail-template-engine.designs` |  statikbe::mail.designs.default\n| render_engine | string | A render engine from config `mail-template-engine.render_engines` | html\n| created_at | timestamp\n| updated_at | timestamp\n| deleted_at | timestamp \n\nIf your application is using Nova you can use [Nova Mail Editor](https://github.com/statikbe/laravel-nova-mail-editor): a tool for editing and creating mail templates.\n \n### Calling the mail class \nIn order to send mails you provide the content and recipient variables, and then send Mail object.  \nThe mail object will now look for any mail template in the database using this Mail class, build it and send the mail.  \n\nAn example:\n```php\nuse Statikbe\\LaravelMailEditor\\Mails\\ResetPasswordMail;\n\n$contentVars = [\n    'nl' =\u003e [ //Optional wrap with locale\n        'url' =\u003e $verificationUrl,\n    ],\n];\n$recipientVars = [\n    'user' =\u003e [\n        //Use an array with mail and optional locale\n        [ \n            'mail' =\u003e $user-\u003eemail, \n            'locale' =\u003e 'en',\n        ],\n        //Or use an object\n        $user \n    ]\n];\n\n$attachments = [\n    'nl' =\u003e [ //Optional wrap with locale\n        'user' =\u003e [ \n            //Using laravel mail attach functionality\n            [ \n                'path' =\u003e $path, \n                'options' =\u003e [\n                    'as' =\u003e 'factuur.pdf',\n                    'mime' =\u003e 'application/pdf',\n                ] \n            ],\n            //Or add an entire file\n            $file \n        ],\n    ]\n];\n\n$mail = new ResetPasswordMail();\n$mail-\u003esendMail($contentVars, $recipientVars);\n```\n\n#### Content variables\nIn this array you assign the values to each key used in the mail template(s). You define the recipients in `getContentVariables` in your mail class. Wrapping the content variables with a locale as key is optional.\n\n#### Recipient variables\nIn this array you assign the mail and locale for each recipient in the mail template(s). You define the recipients in `getRecipientVariables` in your mail class. For more options on how to add the recipient variables look at `\\Statikbe\\LaravelMailEditor\\AbstractMail::formatRecipientArray`.\n\n#### Attachment variables\nIn this array you assign the attachment for each recipient in the mail template(s). You define the recipients in `getRecipientVariables` in your mail class. For more options on how to add the recipient variables look at `\\Statikbe\\LaravelMailEditor\\AbsractMail::formatRecipientArray`. Wrapping the attachments with a locale as key is optional.\n\n## Styling\nThe default design provided by the package comes from [here](https://github.com/leemunroe/responsive-html-email-template).\nYou can publish the views and customise it all you want! \n```\nphp artisan vendor:publish --provider=\"Statikbe\\LaravelMailEditor\\MailEditorServiceProvider\" --tag=views\n```\nYou can provide your own designs by adding them to the `designs` array in the config. Designs are view directories where you store the views for your render engines, F.E. the default HTML engine expects a view called `html.blade.php`. \n\n## Configuration\n\nYou can publish the configuration by running this command:\n```\nphp artisan vendor:publish --tag=mail-template-engine\n```\n\nThe following configuration fields are available:\n\nTODO document configuration\n\n\n## License\nThe MIT License (MIT). Please see [license file](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatikbe%2Flaravel-mail-template-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatikbe%2Flaravel-mail-template-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatikbe%2Flaravel-mail-template-engine/lists"}