kreativabyran/kb-mailer
Composer 安装命令:
composer require kreativabyran/kb-mailer
包简介
Provides a simple way of building and sending templated emails in WordPress
README 文档
README
Installation
Composer
composer require kreativabyran/kb-mailer
Plugin
Download zip-file from the latest release and install as plugin.
Usage
Register email
First you have to register an email that you later can send. This is done with kbm_register_email(), which should be hooked on init.
| param | type | desc |
|---|---|---|
| $id | string |
Email ID. Used for sending. |
| $name | string |
Email name displayed in WP-admin. Also used for email subject. |
| $content_variables | array |
(Optional) Each array element needs a key, which is later used for replacing the variable. The array element value is a description which will be shown in the wp-admin page for building the email. |
Example:
add_action( 'init', function() { if ( function_exists( 'kbm_register_email' ) ) { kbm_register_email( 'contact', 'Contact request', array( 'name' => 'Name of person requesting contact', 'message' => 'Message from person', ) ); } } );
Note that the function_exists() check is only needed when using as plugin, not when installing from composer.
Editing email
Go to wp-admin > KB Mailer to see a list with all registered emails, there you can edit each part of the email, and use the registered content variables in the template.
Send email
Registered emails are sent with kbm_send_email()
| param | type | desc |
|---|---|---|
| $id | string |
Email ID as registered in kbm_register_email(). |
| $to | string |
Email receiver address. |
| $content_variables | array |
(Optional) Element key matches the one registered in kbm_register_email().Value is what should be used the email. |
| $subject | string |
(Optional) Email subject. Name as registered in kbm_register_email() will be used if this is not supplied. |
| $attachments | array |
(Optional) Array of attachments. Paths to files to attach. |
| Example: |
$to = 'contact@example.com'; $name = 'Oskar Modig'; $message = 'Hi! I would really like to get in touch with you.'; if ( function_exists( 'kbm_send_email' ) ) { kbm_send_email( 'contact', $to, array( 'name' => $name, 'message' => $message, ) ); } else { // Failsafe if plugin is unavailable. wp_mail( $to, 'Contact request', "<h1>Contact request from $name</h1><p>$message</p>", array( 'Content-Type: text/html; charset=UTF-8' ) ); }
The failsafe isn't necessary when kb-mailer has been installed from composer.
Configuration
Permissions
KB Mailer defaults to showing the email builder interface in wp-admin to user with the manage_options capability. The required capability can be changed with the kb_mailer_admin_page_capability-filter.
Variable separators
The default variable separator is %. Meaning that %name% entered in the email content will be replaced with the value for that variable. The percentage sign before and/or after the variable id can be replaced with the following filters:
kb_mailer_content_variable_beforekb_mailer_content_variable_after
kreativabyran/kb-mailer 适用场景与选型建议
kreativabyran/kb-mailer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 kreativabyran/kb-mailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kreativabyran/kb-mailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-03-19