matchory/laravel-mailgun-templates-channel
Composer 安装命令:
composer require matchory/laravel-mailgun-templates-channel
包简介
A Laravel notification channel for Mailgun's templated messages.
README 文档
README
Mailgun Templates Messages Notification Channel

Provides a notification channel for Mailgun's message templates to Laravel applications.
This library adds a new notification channel to your app that moves email templates from Laravel to Mailgun. This is useful if, for example, you need to send emails from multiple applications, or need a simple way for non-developers to manage email templates.
Installation
Install the library from composer:
composer require matchory/laravel-mailgun-templates-channel
Configuration
Configuration follows the instructions outlined in the Laravel documentation: You should put your Mailgun credentials in
the config/services.php file:
// ... 'mailgun' => [ // Add your mailing domain as registered on Mailgun 'domain' => env('MAILGUN_DOMAIN', 'mailing.example.com'), // Add your Mailgun secret 'secret' => env('MAILGUN_SECRET'), // Optional: Specify the endpoint of Mailgun's EU API if you're a EU // customer and need to comply to the GDPR 'endpoint' => env('MAILGUN_ENDPOINT', 'https://api.eu.mailgun.net'), ], // ...
Usage
To send message templates, you should first create a template on Mailgun (navigate to "Sending" > "Templates" to manage
your templates in the Mailgun web app). Then, create a new notification with a toMailgun method:
use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Matchory\MailgunTemplatedMessages\Messages\MailgunTemplatedMessage; class TestNotification extends Notification { use Queueable; public function __construct(private readonly int $randomNumber) {} public function toMailgun(mixed $notifiable): MailgunTemplatedMessage { return (new MailgunTemplatedMessage('your_template_name')) ->from('noreply@example.com') ->subject('Test Subject') ->param('foo', 'bar') ->params([ 'some' => 'more data', 'available' => 'in your template', 'name' => $notifiable->name, 'number' => $this->randomNumber ]); } }
Send that notification, and you'll receive an email with the rendered template:
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Notification; // number chosen by fair dice roll Notification::sendNow(Auth::user(), new TestNotification(4));
That's it - you're able to use message templates now!
Advanced usage
The MailgunTemplatedMessage instance exposes several message building methods to add more metadata to your message.
This includes the usual stuff like subject, CC, BCC, recipient, and sender, and also options and params.
By setting additional options, you can control Mailgun features like delayed delivery and tracking; by setting params,
you can add template variables to be used while Mailgun renders the template.
Refer to the Mailgun documentation to learn about the specifics.
Message options
The following methods can be leveraged to handle message options:
use Matchory\MailgunTemplatedMessages\Messages\MailgunTemplatedMessage; $message = new MailgunTemplatedMessage(); // Add an option. // Note that the value can be anything that can be converted to JSON! $message->addOption(name: 'skip-verification', value: false); // Use the fluent methods for chaining several operations together. They all // have an equivalent getter and setter. $message->option(name: 'skip-verification', value: false) ->option('require-tls', true) // Set multiple options at once $message->options([ 'skip-verification' => false, 'require-tls' => true, ]); // Check whether options are set $message->hasOption('require-tls'); // true // Retrieve all options $options = $message->getOptions(); // Remove a previously set option. If the option isn't set, this does nothing $message->removeOption('require-tls'); // Equivalent to the above removeOption() call $message = $message->withoutOption('require-tls');
Template parameters
The following methods can be leveraged to handle template rendering parameters:
use Matchory\MailgunTemplatedMessages\Messages\MailgunTemplatedMessage; $message = new MailgunTemplatedMessage(); // Add an param. // Note that the value can be anything that can be converted to JSON! $message->addParam(name: 'foo', value: 'bar'); // Use the fluent methods for chaining several operations together. They all // have an equivalent getter and setter. $message->param(name: 'foo', value: 'bar') ->param('baz', true) // Set multiple params at once $message->params([ 'foo' => false, 'bar' => true, ]); // Check whether params are set $message->hasParam('foo'); // true // Retrieve all params $params = $message->getParams(); // Remove a previously set param. If the param isn't set, this does nothing $message->removeParam('foo'); // Equivalent to the above removeParam() call $message = $message->withoutParam('foo');
Managing templates
Unfortunately, the Mailgun SDK currently has no facilities to manage message templates, although the API endpoints exist on the Mailgun servers (See this issue for reference).
As soon as the templates API is implemented, we will add managing capabilities to this library - including automatically updating your message templates from local blade files.
Contributions
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue. Don't forget to give the project a star! Thanks again!
License
Distributed under the MIT License. See LICENSE for more information.
matchory/laravel-mailgun-templates-channel 适用场景与选型建议
matchory/laravel-mailgun-templates-channel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.85k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 07 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notifications」 「laravel」 「mailgun」 「channel」 「templated-messages」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 matchory/laravel-mailgun-templates-channel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 matchory/laravel-mailgun-templates-channel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 matchory/laravel-mailgun-templates-channel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
Send emails from multiple domains with mailgun
Mailgun integration for SilverStripe emails
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
Captures outgoing SMS notifications
Alfabank REST API integration
统计信息
- 总下载量: 8.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-13