问题 Laravel 无法将表单发送到我的邮箱
Problem Laravel Can't send a form to my mail
Finally !!! I found the problem and I'm ashamed , I just modified the
bad .env.... As you can see I modified the .env.example and not the
.env !!!! I really appreciate your support . It was just a stupide
mistake ^^
+++
我努力解决这个问题。我需要使用 Laravel 将联系表发送到我的邮箱。也许您更喜欢我的存储库 git.
有错误image : error message
这里是mail.php
<?php return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'a@a.com',
'name' => 'Test'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
我的web.php
<?php
Route::get('contact', 'ContactController@getForm');
Route::post('contact', 'ContactController@postForm');
ContactRequest.php
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ContactRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'nom' => 'required|min:5|max:20|alpha',
'email' => 'required|email',
'texte' => 'required|max:250'
];
}
}
ContactController.php
<?php
namespace App\Http\Controllers;
use Mail;
use App\Http\Requests\ContactRequest;
class ContactController extends Controller {
public function getForm()
{
return view('contact');
}
public function postForm(ContactRequest $request)
{
Mail::send('email_contact', $request->all(), function($message)
{
$message->to('a@a.com')->subject('Contact');
});
return view('confirm');
}
}
.env.example
Image : code
UserController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class UsersController extends Controller
{
public function getInfos()
{
return view('infos');
}
public function postInfos(Request $request)
{
return 'Le nom est ' . $request->input('nom') ." ".$request->input('prenom');
}
}
我不知道问题在哪里,可能在函数_assertResponseCode 但我不知道我能写什么...
已编辑::
Second picture of my security account
New Picture of my security account
您是否在 Gmail 设置中启用了 SMTP?
转到 "Settings",例如单击 "Gears" 图标和 select "Settings"。
点击 "Forwarding and POP/IMAP"。
启用 "IMAP Access" and/or "POP Download"
图片中的错误表明需要身份验证,因此您需要从您的 gmail 帐户启用两步验证。
https://myaccount.google.com/security
您也可以从上面的 link 生成密钥,然后设置您的 MAIL_PASSWORD
而不是您的真实密码。
Finally !!! I found the problem and I'm ashamed , I just modified the bad .env.... As you can see I modified the .env.example and not the .env !!!! I really appreciate your support . It was just a stupide mistake ^^
+++
我努力解决这个问题。我需要使用 Laravel 将联系表发送到我的邮箱。也许您更喜欢我的存储库 git.
有错误image : error message
这里是mail.php
<?php return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'a@a.com',
'name' => 'Test'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
我的web.php
<?php
Route::get('contact', 'ContactController@getForm');
Route::post('contact', 'ContactController@postForm');
ContactRequest.php
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ContactRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'nom' => 'required|min:5|max:20|alpha',
'email' => 'required|email',
'texte' => 'required|max:250'
];
}
}
ContactController.php
<?php
namespace App\Http\Controllers;
use Mail;
use App\Http\Requests\ContactRequest;
class ContactController extends Controller {
public function getForm()
{
return view('contact');
}
public function postForm(ContactRequest $request)
{
Mail::send('email_contact', $request->all(), function($message)
{
$message->to('a@a.com')->subject('Contact');
});
return view('confirm');
}
}
.env.example Image : code
UserController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class UsersController extends Controller
{
public function getInfos()
{
return view('infos');
}
public function postInfos(Request $request)
{
return 'Le nom est ' . $request->input('nom') ." ".$request->input('prenom');
}
}
我不知道问题在哪里,可能在函数_assertResponseCode 但我不知道我能写什么...
已编辑::
Second picture of my security account
New Picture of my security account
您是否在 Gmail 设置中启用了 SMTP?
转到 "Settings",例如单击 "Gears" 图标和 select "Settings"。 点击 "Forwarding and POP/IMAP"。 启用 "IMAP Access" and/or "POP Download"
图片中的错误表明需要身份验证,因此您需要从您的 gmail 帐户启用两步验证。
https://myaccount.google.com/security
您也可以从上面的 link 生成密钥,然后设置您的 MAIL_PASSWORD
而不是您的真实密码。