jlorente/yii2-brevo
Composer 安装命令:
composer require jlorente/yii2-brevo
包简介
Yii2 integration for Brevo (Sendinblue) mailer over brevo-php SDK
README 文档
README
Yii2 mailer connector for Brevo (formerly Sendinblue).
Provides a seamless integration of the official brevo-php SDK into Yii2.
This component lets you send either full custom HTML emails or Brevo transactional templates, and you can deliver them through Brevo’s Transactional REST API (via the official SDK) or through Brevo’s SMTP relay.
Features include dynamic template parameters, custom subjects, attachments, CC/BCC, default sender configuration, and sandbox mode for safe testing.
Installation
Package installation
To install, either run
$ php composer.phar require jlorente/yii2-brevo "*"
or
$ composer require jlorente/yii2-brevo "*"
or add
... "require": { // ... other configurations ... "jlorente/yii2-brevo": "*" }
to the require section of your composer.json file and run the following command from your project directory.
$ composer update
Component configuration
Then configure the component in your Yii2 application (for example in config/main.php or common/config/main.php):
... 'components' => [ // ... other configurations ... 'mailer' => [ 'class' => \jlorente\brevo\Mailer::class, 'apiKey' => env('BREVO_API_KEY'), 'defaultSender' => [ 'email' => 'noreply@your-domain.com', 'name' => 'My App', ], 'sandboxEmail' => 'dev@your-domain.com', // or an array of addresses 'guzzleConfig' => [ 'timeout' => 10.0, // add proxy or other Guzzle options if needed ], 'useFileTransport' => false, 'viewPath' => '@app/mail', ], ], ...
Basic Usage
Yii::$app->mailer->compose() ->setTo('user@example.com') ->setSubject('Hello from Brevo') ->setHtmlBody('<h1>Hello</h1><p>HTML body</p>') ->setTextBody('Hello — plain text body') ->send();
Using Brevo Templates
Yii::$app->mailer->compose() ->setTo('user@example.com') ->setTemplateId(123456) ->setParams([ 'firstName' => 'John', // other template parameters ]) ->send();
Attachments
Attach a file from disk:
Yii::$app->mailer->compose() ->setTo('user@example.com') ->setSubject('Report attached') ->setHtmlBody('<p>Please find the report attached</p>') ->attach('/path/report.pdf', [ 'fileName' => 'report.pdf', 'contentType' => 'application/pdf', ]) ->send();
Attach content from memory:
$binary = file_get_contents('/path/generated.pdf'); Yii::$app->mailer->compose() ->setTo('user@example.com') ->setSubject('In-memory attachment') ->setHtmlBody('<p>See attached file</p>') ->attachContent($binary, [ 'fileName' => 'generated.pdf', 'contentType' => 'application/pdf', ]) ->send();
Inline / Embed Notes
- Methods
embed()andembedContent()exist to satisfy the Yii2MessageInterface. - Warning: the Brevo transactional REST API does not support true inline (CID) images.
Calling these methods will log a warning and the resource will be sent as a regular attachment, not as an inline MIME part.
Sandbox Mode
If sandboxEmail (string or array) is configured, every outgoing email is redirected to that address or list of addresses, ignoring the original recipients.
This is useful for development, staging, or automated tests to prevent accidental delivery.
Technical Notes
- Uses the official
getbrevo/brevo-phpSDK. - A default sender (
defaultSender) is applied if noFromaddress is set on the message. guzzleConfiglets you customize the underlying Guzzle HTTP client (timeouts, proxy, etc.).- After sending, you can access the Brevo response via
Message::getLastResponse()or check exceptions withMessage::getLastException(). - Calls to
embed()orembedContent()will log a Yii warning.
Contributing
- Fork the repository.
- Create a feature branch:
git checkout -b feature/my-feature. - Add tests if possible.
- Submit a pull request with a clear description.
License
Copyright © 2025 José Lorente Martín jose.lorente.martin@gmail.com.
Licensed under the MIT license. See LICENSE.txt for details.
jlorente/yii2-brevo 适用场景与选型建议
jlorente/yii2-brevo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 09 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mailer」 「email」 「sdk」 「transactional」 「yii2」 「sendinblue」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jlorente/yii2-brevo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jlorente/yii2-brevo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jlorente/yii2-brevo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Creates new sare mail transport for laravel applications
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
Mandrill Api Integration for Yii2
Laravel contact us form package to send email and save to database
Build and send emails.
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-18