I am using laravel 7. I want to receive email from user in my gmail account when user submit the contact form in live server.
My .env
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygmail
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
My controller
public function saveContact(Request $request)
{
$this->validate($request, [
'name' => 'required',
'email' => 'required',
'contact_no' => 'required',
'message' => 'required',
]);
$contact = new Contact();
$contact->name = $request->name;
$contact->email = $request->email;
$contact->contact_no = $request->contact_no;
$contact->message = $request->message;
$contact->save();
$data = array(
'name' => $request->name,
'email' => $request->email,
'phone' => $request->contact_no,
'user_message' => $request->message
);
Mail::to('mygmail')
->send(new ContactMail($data));
return back()->with('success', 'Thank you for contacting us.');
}
My contactMail.php
public function build(Request $request)
{
return $this->subject('New contact email')
->from($request->email)
->view('frontend.contact_email')
->with('data', $this->data);
}
I get this error, when i submit the form.
stream_socket_enable_crypto(): Peer certificate CN=domain.com' did not match expected CN=
smtp.gmail.com’
2
Answers
try this in yor .env file
You must also enable access to less secure applications in your Google Acount
Set the keys
verify_peer
,verify_peer_name
, andallow_self_signed
to solve the error.You need to add the following of
configmail.php
: