silktide/templated-emailer
最新稳定版本:0.1.1
Composer 安装命令:
composer require silktide/templated-emailer
包简介
Templated emailer
README 文档
README
Templated emailer
This library simply ties together Symfony's powerful templating engine with the flexibility of Swiftmailer, allowing you to send templated emails easily.
Setup
Without DI
If you're not using DI (or don't know what DI is) there is a helpful factory to create the mailer:
$emailer = \Silktide\TemplatedEmailer\TemplatedEmailerFactory::create('/path/to/templates');
The only required argument is the path to the folder containing your email templates (see Creating a template below).
By default, the factory will set up the class to use PHP's mail() function to send your mail and Symfony's PhpEngine for templating. You can optionally provide a Swiftmailer transport class as the second argument if you want to use a different transport, e.g. SMTP. Here's an example of using an alternative transport:
$transport = \Swift_SmtpTransport::newInstance('smtp.example.org', 25)
->setUsername('your username')
->setPassword('your password');
$emailer = \Silktide\TemplatedEmailer\TemplatedEmailerFactory::create('/example', $transport);
Dependency injection / manual instantiation
The TemplatedEmailer class just requires two arguments, a Symfony template engine and an instance of Swift_Mailer:
/**
* @var \Symfony\Component\Templating\EngineInterface
*/
$templateEngine;
/**
* @var \Swift_Mailer
*/
$emailClient;
$emailer = new \Silktide\TemplatedEmailer\TemplatedEmailer($templateEngine, $emailClient);
Creating a template
Templates are using Symfony's well documented template library. Here's a very basic example:
<h1>An email from myApp</h1>
<p>Dear <?php echo $recipientName; ?></p>
<p><?php echo $message; ?>
The variables in the message are passed through as an array to the send() method (see usage below).
Usage
Before any emails can be sent, you must set a sender:
$emailer->setSender('pat@postman.com', 'Postman Pat');
Sending an email now just requires a recipient, subject, template filename and context:
$this->mailer->send(
'mrsgoggins@greendalepo.com',
'Jess the black and white cat',
'anEmail.php',
[
'recipientName' => 'Mrs Goggins',
'message' => 'Hello!'
]
);
The recipient can also have a name set by using an array in the format ['email@host.tld' => 'Friendly Name']:
$this->mailer->send(
['mrsgoggins@greendalepo.com' => 'Mrs Goggins'],
'Jess the black and white cat',
'anEmail.php',
[
'recipientName' => 'Mrs Goggins',
'message' => 'Hello!'
]
);
silktide/templated-emailer 适用场景与选型建议
silktide/templated-emailer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 silktide/templated-emailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 silktide/templated-emailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2015-09-10