1

Hi Im trying to send a mail but when I try using the Mail::Send but the variables im creating to have the information to which mail it will be send wont go into the Mail::Send part. I dont know why it always tells me undifined variable, when its defined right on top. Here is the code

$result = DB::table('perfil')->where('usuario', $object['usuario'])->first();

        $info = array('confirmation_code' => $result->codigoVerificacion, 'nombre' => $result->nombre);

        $mail = $result->correoVerificado;

        $nombre = $result->nombre.' '.$result->primerPaterno.' '.$result->segundoApellido;

        Mail::send('emails.registro_nuevo_usuario', $info, function($message)
        {

            $message->from('jfeuchter@gmail.com', 'Jurgen Feuchter');

            $message->to($mail, $nombre)
                ->subject('¡Bienvenido a la mejor red social para pedir y dar rides!');
        });

If you need more code ask me for it please :P

'Undefined variable: mail' in \app\controllers\registroController.php:103

Jurgen Feuchter
  • 544
  • 1
  • 7
  • 29
  • what undefined variable? You are leaving out the most critical information :P Ps remove your e-mailaddress.. And did you test the outcome of result? `\dd($result);` Also if you require $result to exists; better use firstOrFail() instead of first() – Luceos Apr 16 '14 at 18:43
  • So where does `$message` come from? – Marc B Apr 16 '14 at 18:44
  • My bad here it is hehehe 'Undefined variable: mail' in C\\app\\controllers\\registroController.php:103 – Jurgen Feuchter Apr 16 '14 at 18:45

1 Answers1

7

$mail comes from outside the closure, so it's not available inside its scope (unlike $message which is passed down as argument by the send() method). You need to pass it by using the use keyword (I believe the same will happen to $nombre)

Mail::send('emails.registro_nuevo_usuario', $info, function($message) use($mail, $nombre)
{
 $message->from('jfeuchter@gmail.com', 'Jurgen Feuchter')
          ->to($mail, $nombre)
          ->subject('¡Bienvenido a la mejor red social para pedir y dar rides!');
});
Damien Pirsy
  • 25,319
  • 8
  • 70
  • 77