{"id":18929430,"url":"https://github.com/thecodingmachine/swift-twig-mail-template","last_synced_at":"2025-04-15T15:30:57.977Z","repository":{"id":57067880,"uuid":"57230749","full_name":"thecodingmachine/swift-twig-mail-template","owner":"thecodingmachine","description":"This package contains a utility class to render Swift mail messages using Twig for templating","archived":false,"fork":false,"pushed_at":"2018-10-12T15:25:08.000Z","size":22,"stargazers_count":3,"open_issues_count":1,"forks_count":10,"subscribers_count":8,"default_branch":"5.0","last_synced_at":"2025-04-10T23:05:12.872Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/thecodingmachine.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}},"created_at":"2016-04-27T16:58:26.000Z","updated_at":"2020-02-18T13:57:08.000Z","dependencies_parsed_at":"2022-08-24T10:20:12.047Z","dependency_job_id":null,"html_url":"https://github.com/thecodingmachine/swift-twig-mail-template","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/thecodingmachine%2Fswift-twig-mail-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fswift-twig-mail-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fswift-twig-mail-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fswift-twig-mail-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodingmachine","download_url":"https://codeload.github.com/thecodingmachine/swift-twig-mail-template/tar.gz/refs/heads/5.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249097817,"owners_count":21212358,"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-08T11:32:41.336Z","updated_at":"2025-04-15T15:30:57.636Z","avatar_url":"https://github.com/thecodingmachine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/thecodingmachine/swift-twig-mail-template.svg?branch=5.0)](https://travis-ci.org/thecodingmachine/swift-twig-mail-template)\n[![Coverage Status](https://coveralls.io/repos/thecodingmachine/swift-twig-mail-template/badge.svg?branch=5.0\u0026service=github)](https://coveralls.io/github/thecodingmachine/swift-twig-mail-template?branch=5.0)\n[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/thecodingmachine/swift-twig-mail-template/badges/quality-score.png?b=5.0)](https://scrutinizer-ci.com/g/thecodingmachine/swift-twig-mail-template?b=5.0)\n[![Code Coverage](https://scrutinizer-ci.com/g/thecodingmachine/swift-twig-mail-template/badges/coverage.png?branch=5.0)](https://scrutinizer-ci.com/g/thecodingmachine/swift-twig-mail-template?b=5.0)\n[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://github.com/ellerbrock/open-source-badge/)\n[![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://github.com/ellerbrock/open-source-badge/)\n\n# Swift Twig Mail Generator\n\nThis package takes a Twig template and generates a Swift mail from this template.\n\n## Installation\n\n```\ncomposer require thecodingmachine/swift-twig-mail-template\n```\n\nOnce installed, you can start creating an instance of the `SwiftTwigMailTemplate` class.\n\nThe `SwiftTwigMailTemplate` represents a mail template that can generate Swift mails.\n\n## Example\n\nBecause we consider that an example is better than everything else...\n\nStart by creating your mail template. Your template should have two blocks:\n\n```twig\n{% block subject %}\n    Your suject\n{% endblock %}\n\n{% block body_html %}\n    Body with HTML.\n{% endblock %}\n```\n\nIf you want you can add another block containing your text body. This block is optional since we can get your the text body directly from the html one.\n\n```twig\n{% block body_text %}\n    Body without HTML.\n{% endblock %}\n```\n\nAlso, you can create a mail with a text body only (and no HTML):\n\n```twig\n{% block subject %}\n    Your suject\n{% endblock %}\n\n{% block body_text %}\n    Body with text only.\n{% endblock %}\n```\n\n\nNow, let's create a `SwiftTwigMailTemplate` instance. This object will generate a `SwiftMail` from the twig template.\n\n```php\n// We assume that $twigEnvironment is a valid TwigEnvironment instance\n$twigSwiftMailTemplate =  new SwiftTwigMailTemplate($twigEnvironment, 'path/to/template.twig');\n\n// The renderMail method generates a Swift mail object.\n$swiftMail = $twigSwiftMailTemplate-\u003erenderMail(['paramKey' =\u003e paramValue]);\n\n// We fill the swift mail with additional information\n$swiftMail-\u003esetFrom('sender@example.com');\n$swiftMail-\u003esetTo('recipient@example.com');\n\n// We assume that $mailer is a valid Swift_Mailer instance\n$mailer-\u003esend($swiftMail);\n```\n\nYou can also embed images directly into the email by using the embedImage function. By embedding an image into the email, most mail clients will display the image directly without printing the traditional warning.\n\nNote: embedImage expects one parameter: the full path to the image file.\n\n```twig\n{% block subject %}\n    Welcome !\n{% endblock %}\n\n{% block body_html %}\n    \u003cimg src=\"{{ embedImage(constant('ROOT_PATH')~'/public/img/header.png') }}\" alt=\"header\"\u003e\n\n    \u003ch1\u003eHello World!\u003c/h1\u003e\n{% endblock %}\n```\n\n### Going further\n\nThe `SwiftTwigMailTemplate` class has been designed with dependency injection in mind. Instances can be easily put in your container for easy reuse.\nFurthermore, the `SwiftTwigMailTemplate` class shares a lot with the `Swift_Mail` class. You can:\n\n* setting the from address \n* setting the from name \n* setting the to address \n* setting the to name \n* setting the Bcc address \n* setting the Bcc name \n* setting the Cc address \n* setting the Cc name \n* setting the ReplyTo address \n* setting the ReplyTo name \n* setting the max line size\n* setting the priority\n* setting the read receip to\n* setting the return path\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Fswift-twig-mail-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodingmachine%2Fswift-twig-mail-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Fswift-twig-mail-template/lists"}