kinglozzer/silverstripe-mailgunner

SilverStripe邮件的Mailgun集成

安装次数: 12,431

依赖项: 0

建议者: 0

安全: 0

星标: 7

关注者: 3

分支: 7

开放问题: 1

类型:silverstripe-module

3.1.1 2018-05-18 13:02 UTC

This package is auto-updated.

Last update: 2024-09-04 22:38:45 UTC


README

Build Status Code Quality Code Coverage Version License

一个通过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);