vulcandigital/silverstripe-sendgrid 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vulcandigital/silverstripe-sendgrid

Composer 安装命令:

composer require vulcandigital/silverstripe-sendgrid

包简介

A module to assist developers in sending template emails via SendGrid

README 文档

README

Build Status codecov Latest Stable Version Total Downloads License

silverstripe-sendgrid

A module to assist developers in sending template emails via SendGrid

Requirements

  • silverstripe/framework: ^4.0

Installation

composer require vulcandigital/silverstripe-sendgrid

Configuration

mysite/_config/sendgrid.yml:

Vulcan\SendGrid\SendGrid:
  api_key: 'REPLACE-WITH-YOUR-API-KEY'

Usage

$sendGrid = \Vulcan\SendGrid\SendGrid::create();
$sendGrid->setSubject("We have a sale for you!");
$sendGrid->setFrom('marketing@example.com');
$sendGrid->setFromName('My Site');
$sendGrid->setReplyTo('sales@example.com');
$sendGrid->addRecipient('reece@vulcandigital.co.nz', 'Reece Alexander', [
    ':salutation' => 'Mr',
    ':button_link' => 'https://example.com/store/offer?id=aASdGdjnklashewjk12321hjkasd213'
]);
$sendGrid->setBody("<p>We thought you'd like this awesome t-shirt!</p>");
$sendGrid->setTemplateId('your-template-id');
$sendGrid->addAttachment(Image::get()->first());
$sendGrid->send();

You can add as many recipients as you want.

Substitutions & Custom Arguments

Substitutions and custom arguments are practically the same thing, the only difference is that custom arguments are applied globally regardless of the recipient where substitutions are variable replacements that can differ per recipient.

Substitutions will always override any custom argument

Substitutions

Substitutions are variables that can be replaced per recipient

$sendGrid->addRecipient('john@doe.com', 'John Doe', [
    ':salutation' => 'Mr',
    ':first_name' => 'John',
    ':last_name' => 'Doe'
]);
$sendGrid->addRecipient('jane@doe.com', 'Jane Doe', [
    ':salutation' => 'Mrs',
    ':first_name' => 'Jane',
    ':last_name' => 'Doe'
]);

Custom Arguments

Custom arguments are applied globally across all recipients unless a substitution has overridden it

$sendGrid->addCustomArg(':year', DBDatetime::now()->Year());

Attachments

You can add as many attachments as you want totalling up to 30 MB. The attachment must be a File object or a subclass of it such as itself or Image.

$file = Image::get()->first();
$sendGrid->addAttachment($file, $filename = null, $forcePublish = false); 

or you can use an absolute path to a file instead:

$sendgrid->addAttachment('/public_html/path/to/image.png'));
$sendgrid->addAttachment(Controller::join_links(Director::baseFolder(), '/path/to/image2.png'));

If you provide $filename, make sure you provide the correct extension as well to prevent any errors

If the provided file is a File object and $forcePublish is set to true and the File you have provided has not been published, it will be forcibly published.

Scheduling

You can schedule emails to be sent at a later date:

$sendGrid->setScheduleTo(DBDatetime::now()->getTimestamp() + 3600); // Schedule to send in 1 hour

Important: Ensure that you have specified your correct timezone in your SendGrid account's settings, otherwise this may have unexpected results.

Your database timezone should also match the timezone you have specified in your account. See Core Environment Variables for information on how to modify the timezone used by your database.

It is always advised when dealing with dates and times in SilverStripe to use the functionality it has provided you as shown in the example above.

Sandbox Mode

$sendGrid->setSandboxMode(true);

If everything is OK, $sendGrid->send() will return true otherwise an error will be thrown.

License

BSD-3-Clause - Vulcan Digital Ltd

vulcandigital/silverstripe-sendgrid 适用场景与选型建议

vulcandigital/silverstripe-sendgrid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 425 次下载、GitHub Stars 达 4, 最近一次更新时间为 2018 年 02 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 vulcandigital/silverstripe-sendgrid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vulcandigital/silverstripe-sendgrid 我们能提供哪些服务?
定制开发 / 二次开发

基于 vulcandigital/silverstripe-sendgrid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 425
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2018-02-01