g1ntas / swiftmailer-sparkpost-bundle
此包已被废弃,不再维护。未建议替代包。
Swiftmailer Sparkpost 传输作为 Symfony 包
v1.0.1
2017-10-10 09:01 UTC
Requires
- php: ~5.6|~7.0
- f500/swiftmailer-sparkpost: ~1.3.4
- symfony/framework-bundle: ~2.3|~3.0
- symfony/swiftmailer-bundle: >=2.3.10
Requires (Dev)
- phpunit/phpunit: ~5.0
- symfony/finder: ~2.3
This package is not auto-updated.
Last update: 2020-08-22 05:41:59 UTC
README
此包为 Swiftmailer 服务添加了一个额外的传输,它使用 Sparkpost API。内部此包集成了 f500/swiftmailer-sparkpost 到您的 Symfony 项目中。
安装
步骤 1: 下载包
打开命令行控制台,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本
$ composer require g1ntas/swiftmailer-sparkpost-bundle
此命令要求您全局安装了 Composer,如 Composer 文档中的安装章节所述。
步骤 2: 启用包
然后,通过将其添加到项目中 app/AppKernel.php 文件中注册的包列表中,来启用此包
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Gintko\Swiftmailer\SparkpostBundle\GintkoSwiftmailerSparkpostBundle(), ); // ... } // ... }
步骤 3: 配置包
通过在配置文件 app/config/config.yml 中添加 API 密钥来配置 Sparkpost
# app/config/config.yml # ... gintko_swiftmailer_sparkpost: api_key: 'SparkPostApiKey'
同时也配置 Swiftmailer 以使用 Sparkpost 传输
# app/config/config.yml # ... swiftmailer: transport: sparkpost # ...
使用
<?php // ... public function sendEmailAction() { $mailer = $this->get('mailer'); $message = $mailer->createMessage() ->setSubject('test') ->setFrom('me@domain.com', 'Me') ->setTo(['john@doe.com' => 'John Doe', 'jane@doe.com']) ->setSubject('...') ->setBody('...'); $mailer->send($message); }
专用消息
<?php // ... public function sendEmailAction() { $mailer = $this->get('mailer'); $message = $mailer->createMessage('sparkpost') ->setFrom('me@domain.com', 'Me') ->setTo(['john@doe.com' => 'John Doe', 'jane@doe.com']) ->setSubject('...') ->setBody('...') ->setCampaignId('...') ->setPerRecipientTags('john@doe.com', ['...']) ->setMetadata(['...' => '...']) ->setPerRecipientMetadata('john@doe.com', ['...' => '...']) ->setSubstitutionData(['...' => '...']) ->setPerRecipientSubstitutionData('john@doe.com', ['...' => '...']) ->setOptions(['...']); $mailer->send($message); }
配置
以下所有指定值都是默认值。
gintko_swiftmailer_sparkpost: api_key: 'SparkPostApiKey' # required ip_pool_probability: 1.0 recipient_override: email: null gmail_style: false message_options: transactional: true open_tracking: false click_tracking: false sandbox: false skip_suppression: false inline_css: false ip_pool: null
这些选项将应用于所有消息,但如果需要,您可以提供每个消息的自定义配置。更多关于这方面的信息,请参阅原始包页面。