简体   繁体   中英

How to manage .env file in order to receive email in contact form in laravel?

I am working on a website in which I have built contact us form which has both controller and html as shown below.

The snippets of controller code is :

{
return view('posting');
}
public function store(Request $request)
{
/*
dd($request->all());
*/   
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'number' => 'required',
'city' => 'required',
'post' => 'required'
]);
}

The snippets of HTML code for the form is:

div class="form-row">
<div class="form-group disney_posting_number pr-4 col-md-6">
   <label class="ml-1" style="width:100%;text-align:left;">number*</label>
   <input type="number" name="number" class="form-control">
   @if ($errors->has('number'))
   <small class="form-text invalid-feedback">{{$errors->first('number')}}</small>
   @endif
</div>
<div class="form-group disney_posting_city pl-4 col-md-6">
   <label class="ml-1" style="width:100%;text-align:left;">city*</label>
   <input type="city" name="city" class="form-control">
   @if ($errors->has('city'))
   <small class="form-text invalid-feedback">{{$errors->first('city')}}</small>
   @endif
</div>
</div>

Now I am not sure what changes I need to do .env file in order to actually start receiving email. At this moment, .env file has the following details:

MAIL_DRIVER=log
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=abc@gmail.com
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls

After filling the form, the information goes inside the log section of the laravel .


Problem Statement :

I am wondering what changes I need to do in the .env file so that I start receiving email. This is the 1st time I am building the form so I am not sure what fields I need to add in the above .env file section in order to make it work actually.

I hope your gmail credentials are correct. Change MAIL_DRIVER from log to smtp.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=abc@gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls

Also run php artisan config:cache to clear your old and cache your updated settings.

EDIT

Login to your gmail account, click on the menu close to your profile pix. Account > Sign In And Security > Sign In to Google, Enable 2 step verification . Then you can generate app password. Use the app password in your .env file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM