I am continuously getting this error 'Class 'App\Http\Controllers\Mail' not found' error in my UserController.php
public function store(CreateUserRequest $request)
{
$result = DB::table('clients')->select('client_code','name','email')
->where('client_code','=',$request->code)
->where('email','=',$request->email)
->first();
if($result){
$tmp_pass = str_random(10);
$user = User::create([
'username' => $result->name,
'email' => $request->email,
'password' => $tmp_pass,
'tmp_pass' => '',
'active' => 0,
'client_code' => $request->code
]);
if($user){
Mail::send('emails.verify',array('username' => $result->name, 'tmp_pass' => $tmp_pass), function($message) use ($user){
$message->to($user->email, $user->username)
->subject('Verify your Account');
});
return Redirect::to('/')
->with('message', 'Thanks for signing up! Please check your email.');
}
else{
return Redirect::to('/')
->with('message', 'Something went wrong');
}
}
else{
Session::flash('message', "Invalid code or email.");
return redirect('/');
}
}
Mail function used to work in Laravel 4 but I am getting errors in Laravel 5. Any help would be appreciated.
Another way is to use Mail facade
In your controller
In Laravel 5.8 I solved it by also adding this in the controller :
THIS:
INSTEAD OF:
Mail
is an alias inside the global namespace. When you want to reference it from inside a namespace (likeApp\Http\Controllers
in your case) you have to either:Prepend a backslash:
Or add a
use
statement before your class declaration:The same goes for the other facades you use. Like
Session
andRedirect
.setup your
app/config/mail.php
than setup in controller:
after this setup mail are send emails if any permission error have showing then click this url and checked this radio button
https://www.google.com/settings/security/lesssecureapps
after configuration it is working fine in #laravel,#symfony and any php framework
thank you