samcbdev/mail-notifier
Composer 安装命令:
composer require samcbdev/mail-notifier
包简介
Mail template generation based on user's design with custom dynamic variables
README 文档
README
The Well Organised mail Notification Manager, Ever
A custom Laravel package for dynamic mail template creation and storage in a database, with the capability to send emails using Laravel Jobs.
Features
- Dynamic Mail Templates: Create, store, and manage dynamic mail templates in the database.
- Filtering: Easily retrieve templates with custom filter conditions.
- Dynamic Content Replacement: Replace dynamic fields within templates.
- Email Sending: Send emails with support for CC, BCC, and attachments.
- Error Handling: Handles exceptions for cases where mail templates are not found.
Tech Stack
- Laravel: A PHP framework for building modern web applications.
- Composer: Dependency manager for PHP.
- MySQL: Relational database management system for storing mail templates.
Installation
- Composer Install
Run the following command to install the package via Composer:
composer require samcbdev/mail-notifier
- Vendor Publish
Publish the package's configuration and other necessary files:
php artisan vendor:publish --tag="mail-notifier" - Migration Run
Run the database migrations to create the necessary tables:
php artisan migrate
Usage Guide
-
Retrieve All Retrieve all mail templates with optional filtering:
Mailer::filterCondition()->get(); // With filters $filter = [ 'custom_fields->comp_id' => 1, ]; Mailer::filterCondition($filter)->get();
-
Retrieve One Retrieve a single mail template with filtering:
$filter = [ 'custom_fields->comp_id' => 1, ]; Mailer::filterCondition($filter, true)->get(); // true returns first matching record
-
Store Store a new mail template:
$data = [ 'template_unique_id' => 'FP', 'custom_fields' => [ // here custom field is json column 'comp_id' => 1 ], 'title' => 'Title', 'subject' => 'Subject', 'content' => 'Content', 'status' => 1 ]; $setUnique = ['template_unique_id', 'custom_fields->comp_id']; Mailer::storeData($setUnique, $data);
-
Edit Edit an existing mail template:
$data = [ 'template_unique_id' => 'FP', 'custom_fields' => [ 'comp_id' => 1 ], 'title' => 'Title', 'subject' => 'Subject', 'content' => 'Content', 'status' => 2 ]; $setUnique = ['template_unique_id', 'custom_fields->comp_id']; Mailer::editData(1, $setUnique, $data);
-
Delete Delete a mail template:
Mailer::deleteData(1); -
Check Dynamic Strings Check for dynamic strings within a mail template:
$filter = [ 'template_unique_id' => 'FP', 'custom_fields->comp_id' => 1, ]; Mailer::filterCondition($filter, true)->checkDynamicFields();
-
Replace Dynamic Strings and Send Mail Replace dynamic fields within a mail template and send an email: setFromAddress is opitonal functional. If needs to change the from email address and mail, add the function before senMail function.
$filter = [ 'template_unique_id' => 'FP', 'custom_fields->comp_id' => 1, ]; $contentArray = [ '[[content_key]]' => 'replacing string against the key', ]; $subjectArray = [ '[[subject_key]]' => 'replacing string against the key' ]; $fromAddr = [ 'name' => 'testing', 'email' => 'from@web.php' ]; $to = ['recipient@example.com']; $ccOrBcc = [ 'cc' => ['cc1@example.com', 'cc2@example.com'], 'bcc' => ['bcc1@example.com'] ]; $attachments = [ storage_path('/app/public/img.jpg'), storage_path('/app/public/pdf.pdf') ]; try { $ret = Mailer::filterCondition($filter, true) ->replaceDynamicFields($contentArray, $subjectArray) ->setFromAddress($fromAddr) ->sendMail($to, $ccOrBcc, $attachments); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { return response()->json([ 'error' => 'Mail Not Send', 'message' => $e->getMessage() ], 404); }
Development
Open your favorite Terminal and run this command.
php artisan queue:work
License
MIT
samcbdev/mail-notifier 适用场景与选型建议
samcbdev/mail-notifier 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 07 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mail notifier」 「email notifications」 「dynamic email templates」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 samcbdev/mail-notifier 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 samcbdev/mail-notifier 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 samcbdev/mail-notifier 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony JustCall Notifier Bridge
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
Mail libraries used by Zimbra Api
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.
NO LIBRARIES socket per page bridge for your Laravel application.
统计信息
- 总下载量: 65
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-11