laravel发送电子邮件调用\u user \u func()错误

myzjeezk  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(354)

我试图发送电子邮件在拉威尔,我正在使用的 mail::send 功能。
这是我的密码:

$data = [
          'title'=>'Some Title',
          'content'=>'Content',
          'email'=> 'email',
          'password'=>'password',
          'remarks'=>'remarks'
      ];

      Mail::send('admin.mails.activate', $data, ['user'=>$user], function ($message) use ($user) {
          $message->to($user->email, $user->name)->subject('Account Activation Email')->from('support@webmail.com');
      });

我试图将$data变量传递给view文件,将$user变量传递给回调函数,以便使用用户的电子邮件发送电子邮件。但它给了我一个错误:

call_user_func() expects parameter 1 to be a valid callback, array must have exactly two members
mrphzbgm

mrphzbgm1#

Mail::send() 接受3个参数(view、data、callback),但您已经给了它4个参数:

Mail::send('admin.mails.activate', $data, ['user'=>$user], function ($message) use ($user) {
    $message->to($user->email, $user->name)->subject('Account Activation Email')->from('support@webmail.com');
});

我猜你是想把 ['user' => $user] 在中排列 $data :

Mail::send('admin.mails.activate', array_merge($data, ['user' => $user]), function ($message) use ($user) {
    $message->to($user->email, $user->name)->subject('Account Activation Email')->from('support@webmail.com');
});

或者:

$data = [
    'title'=>'Some Title',
    'content'=>'Content',
    'email'=> 'email',
    'password'=>'password',
    'remarks'=>'remarks',
    'user' => $user
];

Mail::send('admin.mails.activate', $data, function ($message) use ($user) {
    $message->to($user->email, $user->name)->subject('Account Activation Email')->from('support@webmail.com');
});
3gtaxfhh

3gtaxfhh2#

这就是问题所在

$message->to($user->email, $user->name)

把它改成

$message->to($user->email)

相关问题