rsvpify / laravel-inky
在Laravel中使用Foundation Inky电子邮件模板
v0.9.3
2023-04-07 12:14 UTC
Requires
- illuminate/support: ^5.7|^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/view: ^5.7|^6.0|^7.0|^8.0|^9.0|^10.0
- incentfit/inky: 1.3.6.5
- symfony/dom-crawler: ^2.7|^3.0|^4.0|^5.0
- tijsverkoyen/css-to-inline-styles: ^2.2
Requires (Dev)
- graham-campbell/testbench: ^5.3
- phpunit/phpunit: ^8.0|^9.0
README
允许您在Laravel 6-10中优雅地使用Foundation的Inky电子邮件模板。
任何扩展名为.inky.php
的视图都将使用Inky和Blade同时编译,允许您无缝地一起使用这两种模板引擎。CSS将自动内联,以便在不支持外部样式的电子邮件客户端中工作。
安装
使用composer要求
composer require rsvpify/laravel-inky
用法
有关如何使用Inky和Foundation for Emails CSS的完整用法,请参阅Foundation for Emails文档。
在Laravel中像往常一样使用Mail
Mail::send('emails.welcome', ['name' => $user->name], function ($m) use ($user) { $m->from('hello@app.com', 'Your Application'); $m->to($user->email, $user->name)->subject('Welcome!'); });
您可以为Blade布局创建继承,例如emails/layout.inky.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width"/> </head> <body> @yield('content') </body> </html>
然后创建Inky视图,例如emails/welcome.inky.php
@extends('emails.layout') @section('content') <container> <row> <columns>Welcome, {{ $name }}</columns> </row> </container> @stop
CSS内联
您在inky.php
模板中的<style>
元素中的任何内容都将自动内联。
要将CSS样式表应用到您的inky.php
模板,请不要包含任何<link>
元素。相反,运行php artisan vendor:publish
,这将为您在config
目录中创建一个新的inky.php
文件。此文件包含您想要包含用于Foundation模板的示例样式表。请确保从基本路径引用Foundation CSS文件的位置。您需要从Foundation获取此文件的最新副本,例如在https://foundation.zurb.com/emails.html
'stylesheets' => [
'public/css/foundation-emails.css',
// you can add additional CSS files here to apply to your emails.
]
在上面的数组中,引用任何您想要应用到电子邮件的附加CSS文件。请确保从基本路径开始包含每个文件。
以下是一些关于电子邮件CSS的实用参考:电子邮件客户端CSS支持指南