vladaurbanek/beauty-mail

使用Laravel发送美观的HTML电子邮件

安装: 1

依赖: 0

建议: 0

安全: 0

星星: 0

关注者: 1

分支: 0

公开问题: 0

语言:Blade

1.1.5 2023-02-18 22:26 UTC

This package is auto-updated.

Last update: 2024-09-19 02:00:25 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中配置您的设置,例如logo URL和社交媒体链接

发送您的第一封Beautymail

将其添加到您的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中使用Beautymail了。有关下一步要做什么,请参阅:发送您的第一封Beautymail