亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

流明中未定義的變量

流明中未定義的變量

PHP
瀟湘沐 2022-05-27 10:17:25
我將在流明中使用 gmail smtp 發送電子郵件,一切正常,但一個變量始終未定義,請讓我知道我錯在哪里這是我的代碼<?phpnamespace App\Services;use Illuminate\Support\Facades\Mail;class MailService{    public static function send($mail_to = '', $title = '', $content = '') {        Mail::send('mail', ['title' => $title, 'content' => $content], function ($message) {            $message->from('[email protected]', 'Test Mail');            $message->to($mail_to);        });    }}這是控制器public function register(Request $request){    $rules = [        'name'          => 'required',        'email'         => 'required|email|unique:users',        'password'      => 'required|min:5',        'phone'         => 'required|numeric|min:10',        'business_name' => 'required|unique:users',        'business_type' => 'required'    ];    $this->validate($request, $rules);    $data = $request->all();    $hashPassword = Hash::make($data['password']);    $data['password'] = $hashPassword;    $data['is_activated'] = 'false';    $pin    = mt_rand(1000, 9999);     $token  = hash("sha256", $pin);    $data['token']  = $token;    $data['otp']    = $pin;    $user = User::create($data);    if ($user) {        MailService::send($request->input('email'), 'OTP', $pin);        return response()->json(['response' => true, 'message' => 'User registered Successfully', 'token' => $token], 201);    } else {        return response()->json(['response' => false, 'message' => ' Please check your credentials, Try again'], 400);    }}這是錯誤{消息:“未定義變量:mail_to”,異常:“ErrorException”,文件:“D:\xampp\htdocs\api\app\Services\MailService.php”,行:12,跟蹤:Array(28)}異常:“錯誤異?!蔽募骸癉:\xampp\htdocs\api\app\Services\MailService.php” 行:12 消息:“未定義變量:mail_to”
查看完整描述

1 回答

?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

你失蹤了$mail_to。你需要在函數中使用它,然后你可以使用它,否則你會得到一個未定義的變量錯誤,因為你現在得到它。


use($mail_to)

您的代碼如下所示。


public static function send($mail_to = '', $title = '', $content = '') {

    Mail::send('mail', ['title' => $title, 'content' => $content], function ($message) use($mail_to) {

        $message->from('[email protected]', 'Test Mail');

        $message->to($mail_to);

    });

}


查看完整回答
反對 回復 2022-05-27
  • 1 回答
  • 0 關注
  • 92 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號