Step-1
php artisan make:mail TestMail
Step-2
change In .env File
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=yourmail@gmail.com
MAIL_PASSWORD=hearyourpassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=yourmail@gmail.com
MAIL_FROM_NAME="${APP_NAME}"
Step-3
php artisan serve
Step-4
In Controller ->Function
$details=[
'title'=>"Mail from Laravel",
'body'=>"This mail laravel test mail i'll try",
];
Mail::to("sendermail@gmai.com")->send(new TestMail($details));
return "Mail Send";
Step-5
Change in TestMailFile
public $details;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($details)
{
$this->details=$details;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject('Laravel Mail')->view('demomail');
}
Step-6
Create View Page(demomail.blade.php)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test Mail</title>
</head>
<body>
<h1>{{ $details['title'] }}</h1>
<p>{{ $details['body'] }}</p>
</body>
</html>
Step-7
Create Route for Controller Funation
Grate
ReplyDeletethank you
Deletethank you
ReplyDelete