Make Mail

make mail : php artisan make:mail DemoEmail //located in (http/mail)

Controller

public function mail(Request $request)
{
$mail=new Message;
$mail->name=$request->name;
$mail->email=$request->email;
$mail->phone=$request->phone;
$mail->subject=$request->subject;
$mail->message=$request->message;

$mail->save();
Mail::to(“marufalbashir@gmail.com”)->send(new DemoEmail($mail)); // DemoEmail located  in Mail folder

return redirect()->back()->with(‘success’,’Sucessfully Sent Your Email!’);
}

Config DemoEmail.php [Mail/DemoEmail.php]

use App\Message; // to get message from database

public function __construct(Message $mail)
{
$this->message=$mail;
}

public function build()
{
return $this->view(‘frontend.mail’)->with(‘mail’,$this->message);
}

Set view , Email Template: test_mai.blade.php (view/test_mail.blade.php)

 

Name: {{$mail->name}}

 

Config MailTrap :

Create An account to mailtrap and config .env file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=69ffda48dde551
MAIL_PASSWORD=4cfafca43965a1
MAIL_ENCRYPTION=null

Config sender address at: config/Mail.php

‘from’ => [
‘address’ => env(‘MAIL_FROM_ADDRESS’, ‘hello@example.com’),
‘name’ => env(‘MAIL_FROM_NAME’, ‘Example’),
],

Gmail Config :

MAIL_DRIVER =smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

MAIL_ENCRYPTION=tls

=>Go to gmail settings page and POP/IMAP POP download enable for all mail .

=> Imap Access : Status->enable IMAP

=> Allow Less Security App

Video : https://www.youtube.com/watch?v=zPd6v1ZihWQ