{"id":17865781,"url":"https://github.com/ttskch/twiggedswiftmessagebuilder","last_synced_at":"2026-02-01T03:01:14.154Z","repository":{"id":23303892,"uuid":"26663361","full_name":"ttskch/TwiggedSwiftMessageBuilder","owner":"ttskch","description":"Twig templated Swift_Message builder service.","archived":false,"fork":false,"pushed_at":"2016-09-23T09:03:12.000Z","size":86,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-22T15:52:35.926Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ttskch.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-11-15T00:13:25.000Z","updated_at":"2016-06-04T16:13:36.000Z","dependencies_parsed_at":"2022-08-24T05:00:22.594Z","dependency_job_id":null,"html_url":"https://github.com/ttskch/TwiggedSwiftMessageBuilder","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ttskch/TwiggedSwiftMessageBuilder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttskch%2FTwiggedSwiftMessageBuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttskch%2FTwiggedSwiftMessageBuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttskch%2FTwiggedSwiftMessageBuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttskch%2FTwiggedSwiftMessageBuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ttskch","download_url":"https://codeload.github.com/ttskch/TwiggedSwiftMessageBuilder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttskch%2FTwiggedSwiftMessageBuilder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28965436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T02:14:24.993Z","status":"ssl_error","status_checked_at":"2026-02-01T02:13:55.706Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-10-28T09:24:57.000Z","updated_at":"2026-02-01T03:01:14.130Z","avatar_url":"https://github.com/ttskch.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TwiggedSwiftMessageBuilder\n\n[![Build Status](https://travis-ci.org/ttskch/TwiggedSwiftMessageBuilder.svg?branch=master)](https://travis-ci.org/ttskch/TwiggedSwiftMessageBuilder)\n[![Latest Stable Version](https://poser.pugx.org/ttskch/twigged-swiftmessage-builder/v/stable.svg)](https://packagist.org/packages/ttskch/twigged-swiftmessage-builder)\n[![Total Downloads](https://poser.pugx.org/ttskch/twigged-swiftmessage-builder/downloads.svg)](https://packagist.org/packages/ttskch/twigged-swiftmessage-builder)\n\n`TwiggedSwiftMessageBuilder` class allows you following things:\n\n * to create Twig templated Swift_Message\n * to create inline styled html email from unstyled html and css strings\n * to embed some image files into message body\n\n## Requirements\n\n* PHP 5.3+\n\n## Getting started\n\nFirst add this dependency into your `composer.json`:\n\n```json\n{\n    \"require\": {\n        \"ttskch/twigged-swiftmessage-builder\": \"~2.0\"\n    }\n}\n```\n\nThen you can send Twig templated email as below:\n\n```twig\n{# email.txt.twig #}\n\n{% block from %}no-reply@example.com{% endblock %}\n{% block from_name %}[Example]{% endblock %}\n{% block subject %}Welcome to [Example]!{% endblock %}\n\n{% block body %}\nHello [Example] World!\n{% endblock %}\n```\n\n```php\n// in your application.\n\n$builder = new \\Ttskch\\TwiggedSwiftMessageBuilder\\TwiggedSwiftMessageBuilder($tiwg);  // $twig is an instance of \\Twig_Environment class.\n\n$message = $builder-\u003ebuildMessage('email.txt.twig');\n$message-\u003esetTo('hoge@example.com');\n\n$mailer-\u003esend($message);    // $mailer is an instance of \\Swift_Mailer class.\n```\n\nIn Twig template you can define many things by using `{% block [field-name] %}{% endblock %}`.\nThese fields can be defined.\n\n * from\n * from_name\n * to\n * cc\n * bcc\n * reply_to\n * subject\n * body\n\n## Use variables in Twig template\n\nOffcourse you can pass variables and use them in Twig template as below:\n\n```twig\n{# email.txt.twig #}\n\n{% block subject %}Welcome to {{ site_title }}!{% endblock %}\n```\n\n```php\n// in your application.\n\n$builder = new \\Ttskch\\TwiggedSwiftMessageBuilder\\TwiggedSwiftMessageBuilder($tiwg);\n\n$message = $builder-\u003ebuildMessage('email.txt.twig', array(\n    'site_title' =\u003e 'FooBar Service',\n));\n$message-\u003esetTo('hoge@example.com');\n\n$mailer-\u003esend($message);\n```\n\n## Use inline-styled html email\n\nYou can make inline-styled html from unstyled html and css strings.\nTo allow recipients of your html email to receive it with Gmail, you will have to make inline-styled html body.\n\n```php\n// in your application.\n\n$builder = new \\Ttskch\\TwiggedSwiftMessageBuilder\\TwiggedSwiftMessageBuilder($tiwg);\n\n$message = $builder-\u003ebuildMessage('email.html.twig');\n\n$style = file_get_contents('/path/to/style.css');\n\n$message = $builder-\u003esetInlineStyle($message, $style);\n\n$mailer-\u003esend($message);\n```\n\n\u003e **Note**\n\u003e\n\u003e This functionality is using `mb_convert_encoding()` with `'auto'` internally. So if you use this you **must** set `mbstring.language` in php.ini or call `mb_language('your_language')` on ahead.\n\u003e\n\u003e **注意**\n\u003e\n\u003e この機能は内部的に `mb_convert_encoding()` に `'auto'` を渡して実行します。なので、php.ini で `mbstring.language` を設定するか、`mb_language('Japanese')` を事前に実行しておく必要があります。\n\n## Embed some image files into message body\n\nYou can embed images into message body as below:\n\n```twig\n{# email.html.twig #}\n\n{% block body %}\n\u003cimg src=\"{{ embed_image(image_path) }}\"/\u003e\n{% endblock %}\n```\n\n```php\n// in your application.\n\n$builder = new \\Ttskch\\TwiggedSwiftMessageBuilder\\TwiggedSwiftMessageBuilder($tiwg);\n\n$message = $builder-\u003ebuildMessage('email.html.twig', array(\n    'image_path' =\u003e '/path/to/image/file',\n));\n\n// you can get renderable html with base64 encoded images. (In case you want to print preview.)\n$renderableHtml = $builder-\u003erenderBody($message);\n\n// you must finalize embedding before send message.\n$message = $builder-\u003efinalizeEmbedding($message);\n\n$mailer-\u003esend($message);\n```\n\n## Enjoy!\n\nSee also [functional tests](tests/FunctionalTest.php) to understand basic usages.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttskch%2Ftwiggedswiftmessagebuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fttskch%2Ftwiggedswiftmessagebuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttskch%2Ftwiggedswiftmessagebuilder/lists"}