shaz3e/email-builder 问题修复 & 功能扩展

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

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

shaz3e/email-builder

Composer 安装命令:

composer require shaz3e/email-builder

包简介

Create Email from frontend and use palceholder within email

README 文档

README

A powerful Laravel package for managing dynamic email templates with placeholders, global layouts, and safe image handling — without creating new Mailables for every email.

Packagist Version Packagist Downloads License Laravel Version

Introduction

Email Builder allows you to manage email templates directly from your application database using dynamic placeholders such as {name}, {app_url}, etc.

It is designed for real production systems, where:

  • Emails must remain valid even months later
  • Images should not break historical emails
  • Templates are managed dynamically (not hardcoded Mailables)
  • Global headers and footers are reusable
  • Multiple applications or tenants may exist

Typical use cases:

  • Welcome emails
  • Email verification
  • Password reset
  • Order confirmations
  • System notifications

Features

  • Database-driven email templates
  • Dynamic placeholders
  • Optional global header & footer
  • Inline CSS for maximum email-client compatibility
  • Safe image handling (no broken historical emails)
  • Optional image cleanup via Artisan command
  • Queue or send instantly (configurable)
  • No need to create new Mailable classes

Installation

Install via Composer:

composer require shaz3e/email-builder

Publish Package Assets

Publish Views

php artisan vendor:publish --tag=email-builder-views

Publish Config (Recommended)

php artisan vendor:publish --tag=email-builder-config

Publish Migrations

⚠️ Configure the package before running migrations.

php artisan vendor:publish --tag=email-builder-migrations
php artisan migrate

Quick Start

Send your first email in minutes.

use Shaz3e\EmailBuilder\Services\EmailBuilderService;

$emailBuilder = new EmailBuilderService();

$emailBuilder->sendEmailByKey(
    'welcome_email',
    'user@example.com',
    [
        'name' => 'John Doe',
        'app_name' => config('app.name'),
        'app_url' => route('verification.notice'),
    ]
);

Ensure the welcome_email template exists in the database.

Core Concepts

Email Templates

Stored in the database and identified by a unique key.

Global Header & Footer

Reusable layout applied across templates when enabled.

Placeholders

Dynamic variables like {name} replaced at send time.

Images

Images are stored on disk and referenced via absolute URLs to ensure compatibility across all email clients.

Configuration

config/email-builder.php

return [

    'image' => [
        'allowed_extensions' => ['jpg', 'jpeg', 'png', 'gif'],
        'max_size' => 2048,
    ],

    'queue_emails' => false,

    'log_info' => false,

    'body_column_type' => 'longText',

    'image_cleanup' => [
        'enabled' => true,
        'retention_days' => 180,
        'disk' => 'public',

        'directories' => [
            'global' => [
                'images/email-builder/global-email/header-images',
                'images/email-builder/global-email/footer-images',
                'images/email-builder/global-email/footer-bottom-images',
            ],

            'templates' => [
                'images/email-builder/email-templates/header-images',
                'images/email-builder/email-templates/footer-images',
                'images/email-builder/email-templates/footer-bottom-images',
            ],
        ],
    ],
];

Request Validation Example

use App\Rules\ImageRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreEmailTemplateRequest extends FormRequest
{
    protected function prepareForValidation(): void
    {
        $this->merge([
            'use_global_header' => $this->boolean('use_global_header') ? 1 : 0,
            'use_global_footer' => $this->boolean('use_global_footer') ? 1 : 0,
        ]);
    }

    public function rules(): array
    {
        return [
            'use_global_header' => ['required', 'in:0,1'],
            'use_global_footer' => ['required', 'in:0,1'],

            'header_image' => ['nullable', 'required_if:use_global_header,0', new ImageRule],
            'header_text' => ['required_if:use_global_header,0', 'string'],
            'header_text_color' => ['required_if:use_global_header,0', 'string'],
            'header_background_color' => ['required_if:use_global_header,0', 'string'],

            'footer_image' => ['nullable', 'required_if:use_global_footer,0', new ImageRule],
            'footer_text' => ['required_if:use_global_footer,0', 'string'],
            'footer_text_color' => ['required_if:use_global_footer,0', 'string'],
            'footer_background_color' => ['required_if:use_global_footer,0', 'string'],

            'key' => ['required', 'string', Rule::unique('email_templates', 'key')],
            'name' => ['required', 'string'],
            'subject' => ['required', 'string'],
            'body' => ['required', 'string'],
        ];
    }
}

Image Retention Policy

  • Images are never deleted automatically
  • Prevents broken historical emails
  • Cleanup is explicit and controlled

Cleanup Command

php artisan email-builder:cleanup-images
php artisan email-builder:cleanup-images --days=180
php artisan email-builder:cleanup-images --force

Email Client Compatibility

Designed for:

  • Gmail (web & mobile)
  • Outlook (Windows & macOS)
  • Yahoo Mail
  • iCloud Mail
  • Hotmail
  • Custom webmail clients

Uses conservative HTML and inline CSS.

Contributing

Pull requests are welcome.

GitHub: https://github.com/Shaz3e/email-builder

License

Email Builder is licensed under the MIT License.

Credits

GitHub commit activity

shaz3e/email-builder 适用场景与选型建议

shaz3e/email-builder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.22k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 shaz3e/email-builder 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-24