Mail :: send()在Laravel 5中不起作用 [英] Mail::send() not working in Laravel 5

查看:384
本文介绍了Mail :: send()在Laravel 5中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的UserController.php中不断出现此错误找不到类'App \ Http \ Controllers \ Mail'"错误

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('/');
    }
}

以前在Laravel 4中可以使用邮件功能,但是在Laravel 5中却遇到了错误.任何帮助将不胜感激.

Mail function used to work in Laravel 4 but I am getting errors in Laravel 5. Any help would be appreciated.

推荐答案

Mail全局命名空间中的别名.当您想从名称空间中引用它(例如您的情况下为App\Http\Controllers)时,您必须执行以下操作之一:

Mail is an alias inside the global namespace. When you want to reference it from inside a namespace (like App\Http\Controllers in your case) you have to either:

添加一个反斜杠:

\Mail::send(...)

或在类声明之前添加use语句:

Or add a use statement before your class declaration:

namespace App\Http\Controllers;

use Mail;  // <<<<

class MyController extends Controller {

您使用的其他外墙也是如此.像SessionRedirect.

The same goes for the other facades you use. Like Session and Redirect.

这篇关于Mail :: send()在Laravel 5中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆