Laravel 使用默认电子邮件模板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48346764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel use default email template
提问by Jadasdas
how can I use default email template Laravel in my function Mail send?
如何在我的邮件发送功能中使用默认电子邮件模板 Laravel?
Mail::send('default template?', $data, function($message) use($data) {
$message->to($data['email']);
$message->subject('New email!!!');
});
Do I need to create a new template? By why I can't use default email template? I can edit default template in resources/vendor/mail/html . Please help me use default email template.
我需要创建一个新模板吗?为什么我不能使用默认电子邮件模板?我可以在 resources/vendor/mail/html 中编辑默认模板。请帮我使用默认的电子邮件模板。
采纳答案by Alexey Mezenin
If the view you want to use is resources/views/vendor/mail/html/default.blade.php
, use it:
如果您要使用的视图是resources/views/vendor/mail/html/default.blade.php
,请使用它:
Mail::send('vendor.mail.html.default', $data, function($message) use($data) {
$message->to($data['email']);
$message->subject('New email!!!');
});
回答by Sam Killen
I don't think the template you are referencing is a Laravel mail template. There are a few ways you can use Laravel's default mail templates. You can create a mailable class and build the email up using Laravel's pre-built email markdown, or you can create another blade template which you reference like any other blade template within Laravel.
我认为您引用的模板不是 Laravel 邮件模板。有几种方法可以使用 Laravel 的默认邮件模板。您可以创建一个可邮寄的类并使用 Laravel 的预先构建的电子邮件降价来构建电子邮件,或者您可以创建另一个刀片模板,您可以像 Laravel 中的任何其他刀片模板一样引用它。
Steps:
脚步:
- Create a new blade file in resources/view => mail.default.blade.php
- Add HTML template code for email
- Reference like so
- 在资源/视图中创建一个新的刀片文件 => mail.default.blade.php
- 为电子邮件添加 HTML 模板代码
- 像这样参考
Mail::send('mail.default', $data, function($message) use($data) {
$message->to($data['email']);
$message->subject('New email!!!');
});
OR
或者
In Laravel, each type of email sent by your application is represented as a "mailable" class. These classes are stored in the app/Mail directory. Don't worry if you don't see this directory in your application, since it will be generated for you when you create your first mailable class using the make:mail
command:
在 Laravel 中,您的应用程序发送的每种类型的电子邮件都表示为一个“可邮寄”类。这些类存储在 app/Mail 目录中。如果您在应用程序中没有看到此目录,请不要担心,因为它会在您使用以下make:mail
命令创建第一个可邮寄类时为您生成:
php artisan make:mail OrderShipped
Markdown mailable messagesallow you to take advantage of the pre-built templates and components of mail notifications in your mailables. Since the messages are written in Markdown, Laravel is able to render beautiful, responsive HTML templates for the messages while also automatically generating a plain-text counterpart.
Markdown 可邮寄消息允许您利用可邮寄的邮件通知的预构建模板和组件。由于消息是用 Markdown 编写的,Laravel 能够为消息呈现漂亮的、响应式的 HTML 模板,同时还自动生成纯文本副本。