rumur/wp-mailer
Composer 安装命令:
composer require rumur/wp-mailer
包简介
The wrapper on top of `wp_mail`
关键字:
README 文档
README
Package Installation
composer require rumur/wp-mailer
How to change From Name and From Email?
<?php use Rumur\WordPress\Mailer\Mailer; // This will change it for all emails that being sent via that mailer. Mailer::useAlwaysFromEmail('fromemail@domain.com'); Mailer::useAlwaysFromName('More then a blog.'); // However it can be changed per email only. Mailer::make(wp_get_current_user(), 'My Blog.', 'testemail@blog.com')->send($mailable);
Create New Email Template
<?php namespace App\Emails; use Rumur\WordPress\Mailer\Mailable; use Rumur\WordPress\Mailer\WordPressMailParams; final class Invoice extends Mailable { /** * @var \Order */ protected $order; /** * Invoice constructor. * @param \Order $order */ public function __construct(\Order $order) { $this->order = $order; } /** * Builds an email params. * * @return WordPressMailParams */ public function build(): WordPressMailParams { // Takes Attached files from the order and converts into relative file paths $as_files = array_map(static function ($file) { return get_attached_file($file); }, $this->order->file_ids); $this->setAttachments($as_files); // Also could be attached as id or an array of ids, will transform them to files. $this->addAttachment($this->order->file_ids); // Also could be mixed $this->addAttachment([ $file_id = 2020, $file_path = WP_CONTENT_DIR . '/uploads/2020/05/lorem.png', ]); // ⚠️ OPTIONAL ⚠️ // The subject could be explicitly set or the Email class name will be taken as a subject. $this->subject( sprintf(_x('Invoice Number %d', 'Invoice Subject', 'text-domain'), $this->order->id) ); return parent::build(); } /** * The Main message of an Email. * @return string */ public function body(): string { // TODO: Implement body() method. } }
Basic Usage
<?php use Rumur\WordPress\Mailer\Mailer; use Rumur\WordPress\Mailer\Dispatcher; use Rumur\WordPress\Mailer\WordPressMailParams; $order = OrderRepository::find(214); Mailer::instance() // ⚠️ OPTIONAL ⚠️ // These local options will be used instead of always ones. ->from('Custom From Name', 'custom@domain.com') // If `to` gets a \WP_User instance, // it also will set the locale from user's data. // You also allowed to pass a regular valid email as well. ->to(wp_get_current_user()) // ⚠️ OPTIONAL ⚠️ // Sets the Carbon Copy of the email. ->cc(['carboncopy@domain.com', get_user_by('id', 2222)]) // ⚠️ OPTIONAL ⚠️ // Sets the Blind Carbon Copy of the email. ->bcc('blindcarboncopy@domain.com') // ⚠️ OPTIONAL ⚠️ // Use the `locale` method in order to explicitly set the locale of the email, // otherwise the locale will be taken from a user if a WP_USer has been passed via a `to` method // ⚠️ Note once the email has been dispatched the main blog locale will be restored back ->locale('en_US') // ⚠️ OPTIONAL ⚠️ // This listener will be triggered in case of the mailer encountered with an error ->onFailure(static function (\WP_Error $error, WordPressMailParams $params, Dispatcher $dispatcher) { // Do something with that error. }) // ⚠️ OPTIONAL ⚠️ ->onSuccess(static function (WordPressMailParams $params, Dispatcher $dispatcher) { // Do something with that information. }) // ⚠️ OPTIONAL ⚠️ // The Email could be sent when a WordPress action has been fired. ->sendOnAction('user_payment_completed', new App\Emails\Invoice($order)) // ⚠️ OPTIONAL ⚠️ // The Email could be sent when the condition is `true`. ->sendWhen($order->isPayed(), new App\Emails\Invoice($order)) // ⚠️ OPTIONAL ⚠️ // This method requires a {@link https://github.com/rumur/wp-scheduling} package to be installed // or as a third parameter you could pass a \Closure that substitute a cron setup. // The Email could be postponed by the specific time. // The first parameter takes \DateTimeInterface|int(timestamp)|string(any relative datetime for `strtotime`) ->sendLater('tomorrow noon', new App\Emails\Invoice($order)) // If sending options above did not meet your need // There is the main method that dispatches the email. ->send(new App\Emails\Invoice($order));
License
This package is licensed under the MIT License - see the LICENSE.md file for details.
rumur/wp-mailer 适用场景与选型建议
rumur/wp-mailer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 06 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「wordpress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rumur/wp-mailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rumur/wp-mailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rumur/wp-mailer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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.
Laravel contact us form package to send email and save to database
Must-use plugin integrating WordPress with the Upsun platform: environment awareness, router-cache friendliness, safe preview clones, deploy migrations, Site Health checks, and a wp upsun CLI command.
A plugin for saving emails to a list
Sendy API implementation for Laravel
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-15