雪火/美观邮件

使用 Laravel 发送美观的 HTML 邮件

安装量: 652 862

依赖项: 5

建议者: 0

安全性: 0

星标: 1 219

关注者: 32

分支: 202

语言:Blade

v1.1.7 2023-06-19 18:59 UTC

README

美观邮件使发送美观的响应式 HTML 邮件变得非常简单。它适用于以下情况:

  • 欢迎邮件
  • 密码提醒
  • 发票
  • 数据导出

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

索引

模板

有许多外观美观的 HTML 邮件模板。Campaign Monitor 和 Mailchimp 已经发布了数百个免费模板。将模板适应美观邮件相当简单。如果您做了,请发送一个 PR。

Widgets by Campaign Monitor

Widget Template

Minty by Stamplia

Widget Template

Sunny

Widget Template

安装

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

composer require snowfire/beautymail

安装完成后,将资源发布到您的公共文件夹

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

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

发送您的第一封美观邮件

将以下内容添加到您的 routes/web.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 中使用不同邮件库的说明,请参阅 这篇博客文章

配置美观邮件类和配置参数

为了在 Lumen 上使美观邮件正常工作,您需要将以下内容添加到您的 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");

开始使用美观邮件

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