hipaway-travel / mandrill-bundle
v1.2
2021-01-06 06:56 UTC
Requires
- mandrill/mandrill: 1.*
- symfony/config: >=2.8
- symfony/http-foundation: >=2.8
Requires (Dev)
- phpunit/phpunit: >=5.7.21
- symfony/debug: >=2.8
- symfony/phpunit-bridge: >=2.8
This package is auto-updated.
Last update: 2024-02-26 12:26:56 UTC
README
通过 mandrill.com 发送事务性邮件。此包为 Symfony2 项目提供了一个简单的 API。
消息类中的所有设置都代表 Mandrill API 的属性。请参阅他们的 API 文档以获取详细信息
https://mandrillapp.com/api/docs/messages.html
先决条件
在使用此包之前,您必须注册 Mandrill。
Mandrill 是发送事务性邮件的绝佳方式,并提供详细的先进报告。
Mandrill 每天免费发送有限数量的电子邮件,请参阅网站上的定价部分以获取更多信息
安装
通过 composer
composer require slot/mandrill-bundle
在内核中启用该包
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Slot\MandrillBundle\SlotMandrillBundle(),
);
}
配置
将配置添加到 config.yml。
登录到 Mandrill 并转到 "设置" -> "SMTP 和 API 凭证"。创建一个 API 密钥并在您的 Symfony2 配置中使用它。
# config.yml slot_mandrill: api_key: xxxxx disable_delivery: true # useful for dev/test environment. Default value is 'false' # debug: passed to \Mandrill causing it to output curl requests. Useful to see output # from CLI script. Default value is 'false' debug: true default: sender: info@example.com sender_name: John Doe # Optionally define a sender name (from name) subaccount: Project # Optionally define a subaccount to use proxy: use: true # when you are behing a proxy. Default value is 'false' host: example.com port: 80 user: john password: doe123
现在您已经准备好了,发送您的第一个事务性邮件
使用
简单的控制器示例
<?php // src/Slot/ExampleBundle/Controller/ExampleController.php namespace Slot\ExampleBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; use Slot\MandrillBundle\Message; use Slot\MandrillBundle\Dispatcher; class ExampleController extends Controller { public function indexAction() { $dispatcher = $this->get('slot_mandrill.dispatcher'); $message = new Message(); $message ->setFromEmail('mail@example.com') ->setFromName('Customer Care') ->addTo('max.customer@email.com') ->setSubject('Some Subject') ->setHtml('<html><body><h1>Some Content</h1></body></html>') ->setSubaccount('Project'); $result = $dispatcher->send($message); return new Response('<pre>' . print_r($result, true) . '</pre>'); } }
使用 Handlebars
默认情况下,该包将假定合并语言为 'mailchimp'。您可以使用 $message->setMergeLanguage('handlebars')
来更改此设置