【发布时间】:2021-10-30 14:55:28
【问题描述】:
我想在我的邮件正文中传递变量,我该怎么做。
我在做。
我想发送来自数据库的邮件模板,在该模板中,我已经定义了发送时要替换的变量。
`$record = DB::table('email_templates')->select('content','em_temp_id')->where('em_temp_id',
$request->select_temp)->where('is_active', 1)->first();
$body = htmlspecialchars_decode($record->content);' //the html body
还有我的邮件功能
'Mail::send([],[], function($message) use ($Toarray, $ToCCarray, $ToBCCarray, $subject, $body,
$is_plainOrHtml){
$message->to($Toarray, '');
$message->cc($ToCCarray, '');
$message->bcc($ToBCCarray, '');
$message->subject($subject);
$message->setBody($body, 'text/html'); //for plain text email
});'
数据库中的模板如下:
`<p>Dear {{$userName}},</p>
<p>The {{$service_provider}}, requesting you to join <strong>{{$channel}}</strong> service.
</p>`
要传递的数组:
`$arr_pass['userName'] = 'John';
$arr_pass['service_provider'] = 'abc.com';
$arr_pass['channel'] = 'Tom';`
如何在邮件正文中传递这个数组?
【问题讨论】:
-
尝试使用
with方法。 laravel.com/docs/8.x/mail#via-the-with-method -
这也是我没有的电子邮件模板视图。
标签: laravel