samcbdev/mail-notifier 问题修复 & 功能扩展

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

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

samcbdev/mail-notifier

最新稳定版本:1.0.1

Composer 安装命令:

composer require samcbdev/mail-notifier

包简介

Mail template generation based on user's design with custom dynamic variables

README 文档

README

The Well Organised mail Notification Manager, Ever

A custom Laravel package for dynamic mail template creation and storage in a database, with the capability to send emails using Laravel Jobs.

Features

  • Dynamic Mail Templates: Create, store, and manage dynamic mail templates in the database.
  • Filtering: Easily retrieve templates with custom filter conditions.
  • Dynamic Content Replacement: Replace dynamic fields within templates.
  • Email Sending: Send emails with support for CC, BCC, and attachments.
  • Error Handling: Handles exceptions for cases where mail templates are not found.

Tech Stack

  • Laravel: A PHP framework for building modern web applications.
  • Composer: Dependency manager for PHP.
  • MySQL: Relational database management system for storing mail templates.

Installation

  1. Composer Install Run the following command to install the package via Composer:
    composer require samcbdev/mail-notifier
  2. Vendor Publish Publish the package's configuration and other necessary files:
    php artisan vendor:publish --tag="mail-notifier"
  3. Migration Run Run the database migrations to create the necessary tables:
    php artisan migrate

Usage Guide

  1. Retrieve All Retrieve all mail templates with optional filtering:

    Mailer::filterCondition()->get();
    
    // With filters
    $filter = [
        'custom_fields->comp_id' => 1,
    ];
    Mailer::filterCondition($filter)->get();
  2. Retrieve One Retrieve a single mail template with filtering:

    $filter = [
        'custom_fields->comp_id' => 1,
    ];
    Mailer::filterCondition($filter, true)->get(); // true returns first matching record
  3. Store Store a new mail template:

    $data = [
        'template_unique_id' => 'FP',
        'custom_fields' => [ // here custom field is json column
            'comp_id' => 1
        ],
        'title' => 'Title',
        'subject' => 'Subject',
        'content' => 'Content',
        'status' => 1
    ];
    
    $setUnique = ['template_unique_id', 'custom_fields->comp_id'];
    
    Mailer::storeData($setUnique, $data);
  4. Edit Edit an existing mail template:

    $data = [
        'template_unique_id' => 'FP',
        'custom_fields' => [
            'comp_id' => 1
        ],
        'title' => 'Title',
        'subject' => 'Subject',
        'content' => 'Content',
        'status' => 2
    ];
    
    $setUnique = ['template_unique_id', 'custom_fields->comp_id'];
    
    Mailer::editData(1, $setUnique, $data);
  5. Delete Delete a mail template:

    Mailer::deleteData(1);
  6. Check Dynamic Strings Check for dynamic strings within a mail template:

    $filter = [
        'template_unique_id' => 'FP',
        'custom_fields->comp_id' => 1,
    ];
    Mailer::filterCondition($filter, true)->checkDynamicFields();
  7. Replace Dynamic Strings and Send Mail Replace dynamic fields within a mail template and send an email: setFromAddress is opitonal functional. If needs to change the from email address and mail, add the function before senMail function.

    $filter = [
        'template_unique_id' => 'FP',
        'custom_fields->comp_id' => 1,
    ];
    
    $contentArray = [
        '[[content_key]]' => 'replacing string against the key',
    ];
    
    $subjectArray = [
        '[[subject_key]]' => 'replacing string against the key'
    ];
    
    $fromAddr = [
        'name' => 'testing',
        'email' => 'from@web.php'
    ];
    
    $to = ['recipient@example.com'];
    
    $ccOrBcc = [
        'cc' => ['cc1@example.com', 'cc2@example.com'],
        'bcc' => ['bcc1@example.com']
    ];
    
    $attachments = [
        storage_path('/app/public/img.jpg'),
        storage_path('/app/public/pdf.pdf')
    ];
    
    try {
        $ret = Mailer::filterCondition($filter, true)
            ->replaceDynamicFields($contentArray, $subjectArray)
            ->setFromAddress($fromAddr)
            ->sendMail($to, $ccOrBcc, $attachments);
    } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
        return response()->json([
            'error' => 'Mail Not Send',
            'message' => $e->getMessage()
        ], 404);
    }

Development

Open your favorite Terminal and run this command.

php artisan queue:work

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-11