我正在学习Laravel。我正在使用Mail通过Laravel向我的Gmail帐户发送电子邮件。我已经制作了一个收集电子邮件的表格,然后将其发送到电子邮件。我收到的错误如图所示。 enter image description here
当我尝试直接访问发送页面时,出现此错误。 enter image description here
路线:
Route::post('send','MailController@send');
Route::get('email','MailController@email');
MailController:
public function send(){
Mail::send(new SendMail());
}
public function email(){
return view('email');
}
SendMail:
public function build(request $request)
{
return $this->view('mail',['msg'=>$request->message])->to($request->to);
}
mail.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mail</title>
</head>
<body>
<h1>Welcome, to this mail system {{$msg}}</h1>
</body>
</html>
email.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email</title>
</head>
<body>
<h1>Send Email</h1>
<form action="send" method="post">
{{csrf_field()}}
to: <input type="text" name="to" placeholder="To">
message: <textarea name="message" cols="30" rows="10" placeholder="message"></textarea>
<input type="submit" value="Send">
</form>
</body>
</html>
.env
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=usamaqaisar1919@gmail.com
MAIL_PASSWORD="spear45uet.."
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
有人可以帮助我吗?