首页 > 解决方案 > 如何将变量传递给匿名函数?

问题描述

为什么 Laravel 说电子邮件不是一个已定义的变量???

$title = 'hi';
$content = 'hi';
$email='topher@site.com';

Mail::send('confirmation', ['title' => $title, 'content' => $content], function ($message) {
 $message->from('john@site.com', 'Topher');
 $message->to($email);
});

标签: phplaravelemail

解决方案


你在一个函数中使用它,那是一个不同的范围。use($email)在您的函数参数之后添加。

function($message) use($email)


推荐阅读