代码之家  ›  专栏  ›  技术社区  ›  Geoff_S

Laravel-mail,无法将变量传递到subject,但它在主体中有效

  •  1
  • Geoff_S  · 技术社区  · 6 年前

    $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");
    });
    

    为什么它在身体里用它而不是在这里用它?

    1 回复  |  直到 6 年前
        1
  •  2
  •   ColinMD    6 年前

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

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