lotfio/mail-templator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

lotfio/mail-templator

Composer 安装命令:

composer require lotfio/mail-templator

包简介

mail templator

README 文档

README

mail Preview

License PHP version Coverage Downloads

MailTemplator (Easy templates for your emails).

🔥 Introduction :

MailTemplator is lightweight PHP package that helps you create, edit and customize email templates.

📌 Requirements :

  • PHP >= 8
  • PHPUnit >= 9 (for testing purpose)

🚀 Installation & Use :

    composer require lotfio/mail-templator

⚡ Testing :

    composer test-unit
    composer test-integration

☀️ Static analysis :

    composer psalm

✏️ Usage :

  • Create your custom Mail Template in your preferred folder withing your project.
  • Mail template class name should ends with Template (MyCustomTemplate, MySecondTemplate).
<?php

namespace MyCustomMilTemplates;

use MailTemplator\Templator;
use MailTemplator\Contracts\TemplateInterface;

final class MyTemplate extends Templator implements TemplateInterface
{
    /**
     * render this template method
     *
     * @param  array|null $variables
     * @return string
     */
    public function render(?array $variables = null): string
    {
        return $this->loadTemplate()->parse($variables);
    }
}

☝️ Available Directives

  • @LOGO@, @OPENLINE@, @HEADER@, @CONTENT@, @FOOTER@, @SUBFOOTER@, @POWEREDBY@
  • You can customize and update the content of these directives with setters and also with protected properties
  • Example :
<?php

namespace MyCustomMilTemplates;

use MailTemplator\Templator;
use MailTemplator\Contracts\TemplateInterface;

final class MyTemplate extends Templator implements TemplateInterface
{
    // you can use a protected property
    protected string $logo = '<img src="https://mysite.com/logo.png">';

    // or a protected setter
    protected function setLogo(): void
    {
      $this->logo = '<img src="https://mysite.com/logo.png">';
    }

    // all other directives can be updated the same way
}

✋ Custom directives

<?php

namespace MyCustomMilTemplates;

use MailTemplator\Templator;
use MailTemplator\Contracts\TemplateInterface;

final class MyTemplate extends Templator implements TemplateInterface
{
    // declare your custom directives
    protected string $content = 'Hello @USERNAME@ how are u ?';
}
  • Then you can pass the value with the template setTemplate(new MyTemplate, ['username' => $username])

💪 Custom Static Template

final class MyTemplate extends Templator implements TemplateInterface
{
    /**
     * render this template method
     *
     * @param  array|null $variables
     * @return string
     */
    public function render(?array $variables = null): string
    {
        return $this->loadTemplate(
          'link/to/your/static/tepmlate.html'
        )->parse($variables);
    }
}

📧 Send mail with Templator

  • Send mail with your template
  • Email subject will follow Template class name
// your mailer (PHPMailer or swift)
// should implement MailAdapterInterface
$customMailer = new class implements MailTemplator\Contracts\MailAdapterInterface{
  public function send(string $to, string $subject, string $message): bool
  {
     // your mailer send should be wrapped here
     // $subject will be taken from template class name  if no custom subject provided
  }
}

// create an instance of mail class
$mail = new MailTemplator\Mail(
  $customMailer
);

// set your template
$mail->setTemplate(
  new MyCustomMilTemplates\MyTemplate
);

// send mail with the given template
$mail->send('to');

🚀 Laravel Integration

  • A recommended directory structure should look like this

directory structure

  • Mail folder

    • Templates folder
    • Customer Mailer (PHPmailer or SwiftMailer)
  • Make sure to register your custom mailer to laravel AppServiceProvider

public function register()
{
    // bind custom mailer that implements MailAdapterInterface
    $this->app->bind(MailTemplator\Contracts\MailAdapterInterface::class, function($app){
        return new CustomMailer;
    });
}
  • Example usage withing a controller method
public function resetPassword(MailTemplator\Mail $mail)
{
    // send mail
    $mail->setTemplate(
      new App\Mail\Templates\ResetPasswordTemplate
      )->send('email@site.com');
}

🚁 TODO

  • Adding database templates support

💻 Contributing

  • Thank you for considering to contribute to MailTemplator. All the contribution guidelines are mentioned here.

📃 ChangeLog

🍺 Support the development

  • Share MailTemplator and lets get more stars and more contributors.
  • If this project helped you reduce time to develop, you can give me a cup of coffee :) : Paypal. 💖

📋 License

  • MailTemplator is an open-source software licensed under the MIT license.

lotfio/mail-templator 适用场景与选型建议

lotfio/mail-templator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 11 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 lotfio/mail-templator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 lotfio/mail-templator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-28