kinglozzer / silverstripe-mailgunner
SilverStripe邮件的Mailgun集成
3.1.1
2018-05-18 13:02 UTC
Requires
- mailgun/mailgun-php: ^2.3
- silverstripe/framework: ^3.0
Requires (Dev)
README
一个通过Mailgun API发送邮件的SilverStripe Mailer
类。
安装
$ composer require kinglozzer/silverstripe-mailgunner:^3.0 php-http/curl-client guzzlehttp/psr7
注意:Mailgun PHP库使用HTTPlug,因此如果您想,可以更换HTTP适配器。更多信息请见这里。
配置
通过Config
API设置您的API密钥和域名
--- After: 'silverstripe-mailgun' --- Kinglozzer\SilverStripeMailgunner\Mailer: api_domain: 'samples.mailgun.org' api_key: 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0' --- After: 'silverstripe-mailgun' Only: environment: 'dev' --- # Get your own Postbin ID by visiting http://bin.mailgun.net Kinglozzer\SilverStripeMailgunner\Mailer: api_endpoint: 'http://bin.mailgun.net/62e69d41' debug: true
注意:请确保您始终提供“发件人”地址,或已设置Email.admin_email
配置值。
批量消息
您可以通过单个API调用(不使用Cc或Bcc)使用Mailgun的批量发送功能向一组收件人发送电子邮件。这告诉Mailgun为每个收件人发送一封只包含其名称的to
字段的电子邮件。不使用此功能会导致所有收件人的电子邮件地址都显示在to
字段中。
要发送批量电子邮件,只需将所有要发送的电子邮件地址作为to
字段传递,并添加一个X-Mailgunner-Batch-Message
标题
$email = Email::create( $from = 'noreply@example.com', $to = 'user1@example.com, user2@example.com', $subject = 'My awesome email', $content = 'Hello world!' ); $email->addCustomHeader('X-Mailgunner-Batch-Message', true); $email->send();
SilverStripe版本兼容性
此模块仅在SilverStripe 3.2+上进行了测试,但应该与旧版本兼容。在旧版本的SilverStripe中,您需要在_config.php
中指定要使用的Mailer
实现。
<?php Email::set_mailer(new Kinglozzer\SilverStripeMailgunner\Mailer);