承接 rumur/wp-mailer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 rumur/wp-mailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-15