mmockelyn/beautymail

使用 Laravel 发送美观的 HTML 邮件 | Fork snowfire/beautymail

安装: 2

依赖: 0

建议: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

语言:HTML

7.x-dev 2020-03-04 10:49 UTC

This package is not auto-updated.

Last update: 2024-09-27 07:18:34 UTC


README

Beautymail 可以让您轻松发送美观的响应式 HTML 邮件。适用于以下场景:

  • 欢迎邮件
  • 密码重置提醒
  • 账单
  • 数据导出

如果您使用 Laravel 4,请使用 1.x 分支。

索引

模板

市面上有很多优秀的 HTML 邮件模板。Campaign Monitor 和 Mailchimp 已经发布了数百个免费模板。将模板适配到 Beautymail 非常简单。如果您做了适配,请发送 PR。

Widgets by Campaign Monitor

Widget Template

Minty by Stamplia

Widget Template

Sunny

Widget Template

安装

通过以下命令将包添加到您的 composer.json

composer require snowfire/beautymail

安装完成后,将其添加到 config/app.php 中的提供者列表

Snowfire\Beautymail\BeautymailServiceProvider::class,

将资源发布到您的公共文件夹

php artisan vendor:publish --provider="Snowfire\Beautymail\BeautymailServiceProvider"

config/beautymail.php 中配置您的设置,例如标志 URL 和社交媒体链接

发送您的第一封 Beauty 邮件

将以下内容添加到您的 routes.php

Route::get('/test', function()
{
	$beautymail = app()->make(Snowfire\Beautymail\Beautymail::class);
    $beautymail->send('emails.welcome', [], function($message)
    {
        $message
			->from('bar@example.com')
			->to('foo@example.com', 'John Smith')
			->subject('Welcome!');
    });

});

现在创建 resources/views/emails/welcome.blade.php

@extends('beautymail::templates.widgets')

@section('content')

	@include('beautymail::templates.widgets.articleStart')

		<h4 class="secondary"><strong>Hello World</strong></h4>
		<p>This is a test</p>

	@include('beautymail::templates.widgets.articleEnd')


	@include('beautymail::templates.widgets.newfeatureStart')

		<h4 class="secondary"><strong>Hello World again</strong></h4>
		<p>This is another test</p>

	@include('beautymail::templates.widgets.newfeatureEnd')

@stop

就是这样!

选项

模板: Widgets

为了更改不同部分的颜色,传递一个颜色变量

@include('beautymail::templates.widgets.articleStart', ['color' => '#0000FF'])

Minty 模板示例

@extends('beautymail::templates.minty')

@section('content')

	@include('beautymail::templates.minty.contentStart')
		<tr>
			<td class="title">
				Welcome Steve
			</td>
		</tr>
		<tr>
			<td width="100%" height="10"></td>
		</tr>
		<tr>
			<td class="paragraph">
				This is a paragraph text
			</td>
		</tr>
		<tr>
			<td width="100%" height="25"></td>
		</tr>
		<tr>
			<td class="title">
				This is a heading
			</td>
		</tr>
		<tr>
			<td width="100%" height="10"></td>
		</tr>
		<tr>
			<td class="paragraph">
				More paragraph text.
			</td>
		</tr>
		<tr>
			<td width="100%" height="25"></td>
		</tr>
		<tr>
			<td>
				@include('beautymail::templates.minty.button', ['text' => 'Sign in', 'link' => '#'])
			</td>
		</tr>
		<tr>
			<td width="100%" height="25"></td>
		</tr>
	@include('beautymail::templates.minty.contentEnd')

@stop

Ark 模板示例

@extends('beautymail::templates.ark')

@section('content')

    @include('beautymail::templates.ark.heading', [
		'heading' => 'Hello World!',
		'level' => 'h1'
	])

    @include('beautymail::templates.ark.contentStart')

        <h4 class="secondary"><strong>Hello World</strong></h4>
        <p>This is a test</p>

    @include('beautymail::templates.ark.contentEnd')

    @include('beautymail::templates.ark.heading', [
		'heading' => 'Another headline',
		'level' => 'h2'
	])

    @include('beautymail::templates.ark.contentStart')

        <h4 class="secondary"><strong>Hello World again</strong></h4>
        <p>This is another test</p>

    @include('beautymail::templates.ark.contentEnd')

@stop

Sunny 模板示例

@extends('beautymail::templates.sunny')

@section('content')

    @include ('beautymail::templates.sunny.heading' , [
        'heading' => 'Hello!',
        'level' => 'h1',
    ])

    @include('beautymail::templates.sunny.contentStart')

        <p>Today will be a great day!</p>

    @include('beautymail::templates.sunny.contentEnd')

    @include('beautymail::templates.sunny.button', [
        	'title' => 'Click me',
        	'link' => 'http://google.com'
    ])

@stop

Lumen 支持

为了在 Lumen 上运行,请按照安装说明操作,但除了 artisan vendor:publish 命令外,因为 Lumen 不提供此命令。相反,您必须手动将 vendor/snowfire/beautymail/public/ 中的资源文件夹复制到您的 Lumen 项目的公共文件夹。

请确保还将 beautymail.php 配置文件放入 config 文件夹中(默认情况下在 src/config/settings.php 中可用)

在 Lumen 中启用邮件

之后,您需要使用以下命令安装和配置 illuminate/mailer

composer require illuminate/mail

并将其添加到您的 bootstrap/app.php

$app->withFacades();
$app->register(App\Providers\AppServiceProvider::class);

有关更多详细信息以及如何在 Lumen 中使用不同的邮件库,请参阅 此博客文章

配置 Beautymail 类和配置参数

为了在 Lumen 上运行 Beautymail,您需要将以下内容添加到您的 bootstrap/app.php 以解决缺失的配置文件、参数和类(在注册 BeautymailServiceProvider 之前)

// Provide required path variables
$app->instance('path.config', env("STORAGE_DIR", app()->basePath()) . DIRECTORY_SEPARATOR . 'config');
$app->instance('path.public', env("STORAGE_DIR", app()->basePath()) . DIRECTORY_SEPARATOR . 'public');

// Enable config for beautymail
$app->configure('beautymail');

// Provide class alliases to resolve Request and Config
class_alias(\Illuminate\Support\Facades\Request::class, "\Request");
class_alias(\Illuminate\Support\Facades\Config::class, "\Config");

开始使用 Beautymail

恭喜,您现在可以开始在 Lumen 中使用 bBautmail。有关下一步操作,请参阅:发送您的第一封 Beauty 邮件