hpsweb / beautymail
使用Laravel发送精美的HTML电子邮件
Requires
- php: >=5.4.0
- illuminate/support: 4.*|5.*|^6.0.0|^7.0.0|^8.0.0|^9.0.0
- pelago/emogrifier: ^3.0|^4.0|^5.0|^6.0
README
Beautymail让发送美观的响应式HTML电子邮件变得非常简单。它适用于以下场景:
- 欢迎邮件
- 密码提示
- 发票
- 数据导出
如果你使用Laravel 4,请使用1.x
分支。
索引
模板
现在有很多出色的HTML电子邮件模板。Campaign Monitor和Mailchimp已经发布了数百个免费模板。将模板适配到Beautymail相当简单。如果你做到了,请发送PR。
小部件 由Campaign Monitor
薄荷 由 Stamplia
阳光
安装
通过运行以下命令将包添加到你的composer.json
composer require hpsweb/beautymail
安装完成后,将资产发布到你的公共文件夹
php artisan vendor:publish --provider="Hpsweb\Beautymail\BeautymailServiceProvider"
在config/beautymail.php
中配置你的设置,例如logo URL和社交链接
发送你的第一封美邮件
将以下内容添加到你的routes/web.php
Route::get('/test', function()
{
$beautymail = app()->make(Hpsweb\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
就这样!
选项
模板:小部件
要更改不同部分的颜色,传递一个颜色变量
@include('beautymail::templates.widgets.articleStart', ['color' => '#0000FF'])
薄荷模板示例
@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
阳光模板示例
@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/hpsweb/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);
有关更多详细信息和使用不同邮件库的说明,请参阅此博客文章
配置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了。有关下一步操作的说明,请参阅发送你的第一封美邮件。