rsvpify/laravel-inky

在Laravel中使用Foundation Inky电子邮件模板

v0.9.3 2023-04-07 12:14 UTC

This package is auto-updated.

Last update: 2024-09-07 15:34:01 UTC


README

Actions Status

允许您在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支持指南

许可证

MIT许可证