Laravel发送电子邮件call_user_func()错误

时间:2018-09-25 09:26:19

标签: mysql laravel email laravel-5 laravel-5.6

我正在尝试使用laravel发送电子邮件,而我正在使用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变量传递给视图文件,将$ user变量传递给回调函数,以便可以使用用户的电子邮件发送电子邮件。但这给了我这个错误:

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

2 个答案:

答案 0 :(得分:2)

Mail::send()接受3个参数(视图,数据,回调),但您给了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');
});

答案 1 :(得分:0)

这是问题

<StackPanel>
     <TextBlock Text="{Binding TextName}" FontSize="30"></TextBlock>
     <TextBox Text="{Binding TextName}"></TextBox>
</StackPanel>

将其更改为

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