fibis/laravel-inky

在 Laravel 中使用 Foundation Inky 邮件模板

0.8.0 2023-11-01 14:42 UTC

README

允许您在 Laravel 5 中优雅地使用 Foundation 的 Inky 邮件模板。此版本是可工作的!

任何以 .inky.php 扩展名的视图都将同时与 Inky 和 Blade 编译,让您可以无缝地同时使用这两个模板引擎。CSS 将自动内联,以便在不支持外部样式的电子邮件客户端中正常工作。

安装

使用 composer 需求

composer require fibis/laravel-inky

安装后,您需要注册服务提供者。打开 config/app.php 并将以下内容添加到 providers 键中

fibis\LaravelInky\InkyServiceProvider::class

使用方法

有关如何使用 Inky 和 Foundation for Emails CSS 的完整使用说明,请参阅 Foundation for Emails 文档

创建 Inky 视图,例如 emails/welcome.inky.php

<container>
  <row>
    <columns>Welcome, {{ $name }}</columns>
  </row>
</container>

在 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 布局的 Inky 视图,例如 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"/>
  <link rel="stylesheet" href="foundation-emails.css">
</head>
<body>
  @yield('content')
</body>
</html>

然后

@extends('emails.layout')

@section('content')
  <container>
    <row>
      <columns>Welcome, {{ $name }}</columns>
    </row>
  </container>
@stop

CSS 内联

<style><link rel="stylesheet"> 将自动内联。

您的 <link rel="stylesheet">href 位置解析到 resources/assets/css 目录,因此在上述示例中它期望在 resources/assets/css/foundation-emails.css 中有一些 CSS。

以下是一个关于电子邮件中 CSS 的便捷参考:[CSS 支持指南](https://www.campaignmonitor.com/css/)

许可证

MIT 许可证