Send e-mail taking data from a Database?

2

Hello friends, I have a problem with only one line of code that no matter how hard I search, I did not find any solution.

Use laravel: 5.6 Mysql-MariaDB

I have this:

And in the part of $message->$usuario->email that is to the user that the mail will be sent. I get this error attached below the code

public function restoremail(Request $request)
    {

    $correo=DB::table('usuarios')
        ->where('email', '=', $request->get('email'))
        ->get();  
        if(count($correo) > 0)
        {

            $usuario=Usuarios::findOrFail($correo[0]->id_usu);
             $data = array(
    'contrasena'=>$usuario->contrasena,
);
            Mail::send('emails.restore', $data, function($message){
        $message->from('[email protected]','Helle Mexico Team');
        $message->to($usuario->email)->subject('Mensaje de prueba helloteam');

    });
     return view('Home.principal');
        }
        else
        {
             return view('error');
        }

In what way can I make the user enter his mail so that he can see his password in his inbox, and re-decal only that part where the system has to take the mail, thanks for your help!

    
asked by Dohko19 22.06.2018 в 02:21
source

1 answer

1

It does not matter much the database, what happens is that you can not use a variable that is not passed to callback , the third parameter of Mail::send() is a callback and is where you have to pass the parameter with a use , in your case $usuario .

With that little explanation your function would be as follows:

Mail::send('emails.restore', $data, function($message) use ($usuario){
    $message->from('[email protected]','Helle Mexico Team');
    $message->to($usuario->email)->subject('Mensaje de prueba helloteam');

});
    
answered by 22.06.2018 / 02:53
source