0

I want to sent thanks mail when users regist our service. But, This code is error Undefined variable: fhbvuileb in $message->to($fhbvuileb). Help ME!!!

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Mail;

class RegisterController extends Controller
{

  /** ~~~ **/

  protected function create(array $data)
  {

    $fhbvuileb = $data['email'];
    Mail::send('emails.user_register', ["message" => "Hello!"], function($message) {
      $message->to($fhbvuileb)
              ->subject("Thank you!!!");
    });
    return User::create([
      'name' => $data['name'],
      'email' => $data['email'],
      'password' => Hash::make($data['password']),
    ]);

  }
}

1

2 Answers 2

2

You need to use the variable inside the Mail callback function. What you have written is called Closure, and hence the variable is not available inside the closure function scope.

There is a keyword in PHP called use which makes this $fhbvuileb inside the function.

$fhbvuileb = $data['email'];
    Mail::send('emails.user_register', ["message" => "Hello!"], function($message) use($fhbvuileb) {
      $message->to($fhbvuileb)
              ->subject("Thank you!!!");
    });
Sign up to request clarification or add additional context in comments.

Comments

0

You forgot to use language construct use() to pass any argument from the parent scope

   Try this:
    Mail::send('emails.user_register', ["message" => "Hello!"], function($message) use($fhbvuileb) {
              $message->to($fhbvuileb)
                      ->subject("Thank you!!!");
            });

1 Comment

Pasting code isn't an answer. Please explain what your code fixed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.