georgringer / templatedmail
更好的HTML电子邮件模板
dev-tests
2019-10-27 23:29 UTC
Requires
- pelago/emogrifier: ^3.0
- typo3/cms-core: ^10
Requires (Dev)
Replaces
- georgringer/templatedmail: dev-tests
- typo3-ter/templatedmail: dev-tests
This package is auto-updated.
Last update: 2024-08-28 10:36:47 UTC
README
此扩展是一个如何改进邮件模板的证明概念。计划是与TYPO3 10一起分发此代码,并为9x提供扩展。
优点
- 所有邮件共享相同的布局,这使得样式化邮件更容易
- 创建漂亮的邮件更快
要求
- TYPO3 10
- PHP 7.2
使用方法
$templatedEmail = GeneralUtility::makeInstance(TemplatedEmail::class); $templatedEmail ->to('dummy@example.org') ->from(new NamedAddress('noreply@example.org', 'TYPO3')) ->subject('A mail') ->htmlContent('<h1>Hello</h1> an example') ->textContent('Hello' . LF . 'an example') ->send();
此示例将发送包含以下部分的邮件
更多示例
这些示例也可以通过CLI使用 ./web/bin/typo3 mail:template
调用。
使用单个模板文件
$templatedEmail = GeneralUtility::makeInstance(TemplatedEmail::class); $templatedEmail ->to('dummy@example.org') ->from(new NamedAddress('noreply@example.org', 'TYPO3')) ->subject('A mail') ->context(['title' => 'My title']) ->htmlTemplateFile('EXT:templatedmail/Resources/Private/Templates/Examples/Example.html') ->send();
使用自定义模板路径
$templatedEmail = GeneralUtility::makeInstance(TemplatedEmail::class); $templatedEmail ->to('dummy@example.org') ->from(new NamedAddress('noreply@example.org', 'TYPO3')) ->subject('A mail') ->setTemplateRootPaths(['EXT:dummy/Resources/Private/Templates/']) ->setLayoutRootPaths(['EXT:dummy/Resources/Private/Layouts/']) ->context(['title' => 'My title']) ->htmlByTemplate('Examples/Simple') ->textByTemplate('Examples/Simple') ->send();
提供自定义翻译
$templatedEmail = GeneralUtility::makeInstance(TemplatedEmail::class); $templatedEmail ->to('dummy@example.org') ->from(new NamedAddress('noreply@example.org', 'TYPO3')) ->subject('A mail') ->setLanguage('de') ->context(['title' => 'My title']) ->htmlTemplateFile('EXT:templatedmail/Resources/Private/Templates/Examples/Example.html') ->send();
<f:section name="content"> <h1>{f:translate(languageKey:defaults.language,key:'LLL:EXT:templatedmail/Resources/Private/Language/dummy.xml:good_morning')}, {title}</h1> </f:section>
添加内联图像
使用提供的ViewHelper正确附加图像。
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:email="http://typo3.org/ns/GeorgRinger/Templatedmail/ViewHelpers" data-namespace-typo3-fluid="true"> <f:layout name="Simple"/> <f:section name="content"> <email:mailImage mail="{mailMessage}" src="fileadmin/my-files/CA191.JPG" width="100" /> </f:section> </html>
配置
路径在网站配置中配置
templatedMail: templateRootPath: EXT:templatedmail/Resources/Private/Templates/ partialRootPath: EXT:templatedmail/Resources/Private/Partials/ layoutRootPath: EXT:templatedmail/Resources/Private/Layouts/
如果通过CLI发送邮件,可以使用 $templatedEmail->setSite($site);
设置使用的网站。