Laravel Email 设置多个模板(例如更改密码模板、详情订单模板、新用户通知模板)
目前,我知道 Laravel 已经提供了邮件模板。但只有一个模板。如何创建其他模板并在发送电子邮件之前告知需要使用哪个模板。
public function send_email_package()
{
$details=[
'greeting' => 'Testing Rental Package',
'body' => 'Thank You, You Recieve Package A',
'actiontext' => 'Check Status',
'actionurl' => '#',
'lastline' => 'Collect Package at Branch A',
];
Notification::route('mail', '[email protected]')
->route('mail', '[email protected]')
->notify(new RentalPackageProcessing($details));
dd('email-sended');
}
在这里如何指定我需要使用哪个模板。
像这样的示例
- send_email_package()->use_template_package_a
- send_change_password()->use_template_package_b
- send_notification_blabla()->use_template_package_d
Currently, I know Laravel has shipped mail templates. but only one template. How to create other templates and tell which template need to use before sending an email.
public function send_email_package()
{
$details=[
'greeting' => 'Testing Rental Package',
'body' => 'Thank You, You Recieve Package A',
'actiontext' => 'Check Status',
'actionurl' => '#',
'lastline' => 'Collect Package at Branch A',
];
Notification::route('mail', '[email protected]')
->route('mail', '[email protected]')
->notify(new RentalPackageProcessing($details));
dd('email-sended');
}
In here how to specify which template need I use.
Example like this
- send_email_package()->use_template_package_a
- send_change_password()->use_template_package_b
- send_notification_blabla()->use_template_package_d
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建多个模板来发送电子邮件。最好的方法是:
创建一个名为“emails”的文件夹:“resources”>浏览次数>电子邮件”。
创建电子邮件模板:您可以使用 litmus,这是一个提供各种模板的免费网站 https://litmus .com/community/templates。
在模板中,您可以放置需要在电子邮件中显示的变量,在您的情况下是 $details 变量。
执行命令 php artisan make:mail RentalEmail ,这样就创建了一个配置文件,可以传递需要发送的数据,位于“App\Mail\RentEmail”
RentEmail 文件中,放入你要发送的数据在构造函数中接受,在
build().
方法中调用例如:
然后你可以调用 RentMail 类,如下所示:
Mail::to($user->email)->send(new RentMail($x, $y->email));
要使其在单个类中动态化,您可以传递一个变量作为参数来使用您想要的模板。例如 (
->view($xTemplate)
)You can create multiple templates to send emails. The best way to do it is:
Create a folder called 'emails': 'resources > views > emails'.
Create an email template: You can use litmus, a free site for templates of all kinds https://litmus.com/community/templates.
Within the template you can place the variables that need to be displayed in the email, in your case the $details variable.
Execute command php artisan make:mail RentalEmail , so that a configuration file is created and you can pass the data you need to send, located in "App\Mail\RentEmail"
In the RentEmail file, put the data that you will accept in the constructor, to be called in the
build().
methodEx:
Then you can call the RentMail class, like this:
Mail::to($user->email)->send(new RentMail($x, $y->email));
To make it dynamic in a single class, you can pass a variable as a parameter to use the template you want. Ex (
->view($xTemplate)
)