我将在流明中使用 gmail smtp 发送电子邮件,一切正常,但一个变量始终未定义,请让我知道我错在哪里
这是我的代码
<?php
namespace 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('noreply@gmail.com', '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)}
异常:“错误异常”
文件:“D:\xampp\htdocs\api\app\Services\MailService.php” 行:12 消息:“未定义变量:mail_to”
慕尼黑的夜晚无繁华