dansmaculotte/laravel-mail-template 问题修复 & 功能扩展

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

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

dansmaculotte/laravel-mail-template

最新稳定版本:v4.0.1

Composer 安装命令:

composer require dansmaculotte/laravel-mail-template

包简介

A mail template driver to send emails with

README 文档

README

Latest Version Total Downloads Build Status Quality Score Code Coverage

This package allows you to send emails via mail service providers template's engine.

There are 5 drivers available:

There is also and log and null driver for testing and debug purpose.

Installation

Requirements

  • PHP 8.1

You can install the package via composer:

composer require dansmaculotte/laravel-mail-template

The package will automatically register itself.

To publish the config file to config/mail-template.php run:

php artisan vendor:publish --provider="DansMaCulotte\MailTemplate\MailTemplateServiceProvider"

Finally, install the email service package needed:

  • Mailjet
composer require mailjet/mailjet-apiv3-php
  • Mailchimp
composer require mailchimp/transactional
  • SendGrid
composer require sendgrid/sendgrid
  • Mailgun
composer require mailgun/mailgun-php
  • SendinBlue
composer require sendinblue/api-v3-sdk

Usage

Configure your mail template driver and credentials in config/mail-template.php.

Basic

After you've installed the package and filled in the values in the config-file working with this package will be a breeze. All the following examples use the facade. Don't forget to import it at the top of your file.

use MailTemplate;
$mailTemplate = MailTemplate::make()
    ->setSubject('Welcome aboard')
    ->setFrom(config('mail.name'), config('mail.email'))
    ->setRecipient('Recipient Name', 'recipient@email.com')
    ->setLanguage('en')
    ->setTemplate('welcome-aboard')
    ->setVariables([
        'first_name' => 'Recipient',
    ]);
    
$response = $mailTemplate->send();

If an error occurs in the send method it will throw a SendError::responseError exception.

Via Notification

Create a new notification via php artisan:

php artisan make:notification WelcomeNotification

Set via to MailTemplateChannel:

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return [MailTemplateChannel::class];
}

Implement toMailTemplate method and prepare your template:

public function toMailTemplate($notifiable)
{
    return MailTemplate::prepare(
        'Welcome aboard',
        [
            'name' => config('mail.from.name'),
            'email' => config('mail.from.email'),
        ],
        [
            'name' => $notifiable->full_name,
            'email' => $notifiable->email,
        ],
        $notifiable->preferredLocale(),
        'welcome-aboard',
        [
            'first_name' => $notifiable->first_name
        ]
    );
}

And that's it. When MailTemplateChannel will receive the notification it will automatically call send method from MailTemplate facade.

Mailjet Specifics

Mailjet API allows to set an email to debug templates. When a template error is encountered on email sending, Mailjet sends an error report to this mailbox. To do so, set the email in config/mail-template.php, in key mailjet.debug_email.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 35
  • Watchers: 4
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固