rpsimao/beautymail

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

维护者

详细信息

github.com/rpsimao/Beautymail

源代码

安装: 142

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 0

分支: 204

语言:Blade

v1.2.6 2024-03-16 20:46 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

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

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

config/beautymail.php中配置您的设置,如logo 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/rpsimao/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了。有关下一步操作的详细信息,请参阅发送第一封美观邮件