wai/emails

Laravel 5.5+ 的电子邮件模板

1.2.5 2020-06-18 09:07 UTC

This package is auto-updated.

Last update: 2024-09-29 05:02:00 UTC


README

用于创建 blade 电子邮件的 Laravel 框架包。

基本示例
  $email = \Wai\Emails\Email::create('emails.default')->setTheme('default')->strict();

  $email->emailBackgroundColor = '#000';
  
  $email->returnView($context);

安装

通过 composer 安装此包

composer require wai/emails

如果使用 Laravel 5.1 到 5.4,注册 ServiceProvider 和(可选) Facade

// config/app.php

'providers' => [
    ...
    Wai\Emails\EmailServiceProvider::class

];

接下来,使用以下 artisan 命令发布配置文件。

php artisan vendor:publish --provider="Wai\Emails\EmailServiceProvider"

或者使用 Laravel 5.5

php artisan vendor:publish

视图

将包中的 blade 文件发布到您的项目后。您应该有一个包含各种电子邮件构建块的默认电子邮件 blade。这些构建块用于创建在大多数电子邮件客户端上受支持的自己的自定义电子邮件。

构建块包括

  • 全宽图像
  • 带文本/按钮覆盖的背景图像
  • 带文本/按钮的图像
  • 纯文本
  • 包含图像/文本/按钮的三列布局
  • 包含图像/文本/按钮的两列布局
  • 左/右缩略图布局,包含图像/文本/按钮
  • 电子邮件顶部和/或底部的全出血部分
  • 页脚和页眉
  • 多个内联图像
  • 空白填充

因此,如果您想创建自定义电子邮件,只需复制默认的电子邮件 blade,然后开始添加/删除构建块。

主题

此包还允许您自定义电子邮件元素,如背景颜色、文本字体大小和颜色等。

要自定义这些值中的任何一项,您可以通过手动覆盖 blade 中的默认值或在传递给 blade 的上下文中设置值来实现。

例如

在控制器中

$email = \Wai\Emails\Email::create('emails.default')->setTheme('default')->strict();

$email->emailBackgroundColor = '#000'; // Will change the email background color to Black

return $email->returnView($context);

可变属性列表

  • h1Color
  • h1FontSize
  • h1FontWeight
  • h1Margin
  • h1TextAlign
  • h2Color
  • h2FontSize
  • h2FontWeight
  • h2Margin
  • h3TextAlign
  • h3Color
  • h3FontSize
  • h3FontWeight
  • h3Margin
  • h3TextAlign
  • h4Color
  • h4FontSize
  • h4FontWeight
  • h4Margin
  • h4TextAlign
  • h5Color
  • h5FontSize
  • h5FontWeight
  • h5Margin
  • h5TextAlign
  • h6Color
  • h6FontSize
  • h6FontWeight
  • h6Margin
  • h6TextAlign
  • pColor
  • pFontSize
  • pFontWeight
  • pMargin
  • pTextAlign
  • buttonColor
  • buttonHoverColor
  • buttonTextColor
  • buttonFontSize
  • buttonBorderRadius
  • emailBackGroundColor
  • emailBodyBackgroundColor
  • emailElementBackgroundColor
  • webfontUrl
  • webfontName
  • fullBleedTopShow
  • fullBleedTopBackgroundColor
  • fullBleedTopText
  • fullBleedTopTextColor
  • fullBleedTopTextFontSize
  • fullBleedTopTextPadding
  • fullBleedTopTextAlign
  • fullBleedTopImgFullWidth
  • fullBleedTopImgUrl
  • fullBleedTopImgHref
  • fullBleedTopImgWidth
  • fullBleedTopImgHeight
  • fullBleedTopImgPadding
  • fullBleedTopImgAlt
  • fullBleedTopImgAltBackgroundColor
  • fullBleedTopImgAltColor
  • fullBleedBottomShow
  • fullBleedBottomBackgroundColor
  • fullBleedBottomText
  • fullBleedBottomTextColor
  • fullBleedBottomTextFontSize
  • fullBleedBottomTextPadding
  • fullBleedBottomTextAlign
  • fullBleedBottomImgFullWidth
  • fullBleedBottomImgUrl
  • fullBleedBottomImgHref
  • fullBleedBottomImgWidth
  • fullBleedBottomImgHeight
  • fullBleedBottomImgPadding
  • fullBleedBottomImgAlt
  • fullBleedBottomImgAltBackgroundColor
  • fullBleedBottomImgAltColor
  • headerShow
  • headerImgFullWidth
  • headerImgAlign
  • headerImgUrl
  • headerImgHref
  • headerImgWidth
  • headerImgHeight
  • headerImgPadding
  • headerImgTopSpacerHeight
  • headerImgBottomSpacerHeight
  • headerImgElementBackgroundColor
  • headerImgAlt
  • headerImgAltBackgroundColor
  • headerImgAltColor
  • footerShow
  • footerBackgroundColor
  • footerViewAsWebPageUrl
  • footerViewAsWebPageColor
  • footerViewAsWebPageTextDecoration
  • footerViewAsWebPageText
  • footerUnsubscribeUrl
  • 页脚取消订阅颜色
  • 页脚取消订阅文本装饰
  • 页脚取消订阅文本
  • 页脚自定义文本
  • 页脚文本间距
  • 页脚文本字体大小
  • 页脚文本对齐方式
  • 页脚文本颜色

在Blade中

@include('emails.sections.text_block', [
    'background' => $settings->email->elementBackgroundColor,
    'text' => 'Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium lobortis rhoncus ut erat.',
    'textPadding' => '40px',
    'textColor' => $settings->p->color,
    'textAlign' => 'left',
    'textFontSize' => $settings->p->fontSize
])

最后,为了发送刚刚创建的电子邮件,您只需将Blade传递给Laravel Mail即可

$email = \Wai\Emails\Email::create('emails.default')->setTheme('default')->strict();

$subject = 'Testing Blade Emails';
$to = 'Example';

$settings->send($context, function ($m) use ($subject, $to) {
    $m->to('info@example.com', $to);
    $m->subject($subject);
});

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。