为了账号安全,请及时绑定邮箱和手机立即绑定

Laravel 邮件,无法将变量传递到主题中,但它可以在正文中使用

Laravel 邮件,无法将变量传递到主题中,但它可以在正文中使用

PHP
慕森王 2023-08-06 14:49:52
我正在发送一封简单的电子邮件,需要在正文和主题中使用变量。将变量传递到正文中效果很好,但在我的主题行上失败并显示未定义的变量$body = "Attached is the " .$name. " Report for ".date('Y-m-d');Mail::raw($body , function ($message) use ($emails,$filepath,$filename) {    $message->from('noreply@test.com', 'webmail');    $message->attach(storage_path($filepath.'/'.$filename.'.xlsx'));    foreach ($emails['to'] as $email) {        $message->to($email);    }    foreach ($emails['cc'] as $email) {        $message->cc($email);    }    $message->subject("Report for " .$name. " account");});为什么这里用的是body而不是subject呢?
查看完整描述

1 回答

?
largeQ

TA贡献2039条经验 获得超7个赞

您需要将名称传递到函数的 use 语句中。

它没有定义,因为它没有传递到回调函数中。

Mail::raw($body , function ($message) use ($emails,$filepath,$filename,$name) {


查看完整回答
反对 回复 2023-08-06
  • 1 回答
  • 0 关注
  • 50 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信