Hey Artisan
Hope you are doing well. Today i am going to discuss about laravel email. Now i will show you how to send email in laravel 7. Earlier i showed many tutorial about laravel email.
Markdown mail utilizing mailable class, We sent mail utilizing laravel event etc. Now i am going to show you how we can send email in laravel 7. I will show you step by step. Hope you guys will relish this laravel email tutorial.
Afore sending laravel email, if you don't ken how to send it, then first check this two tutorial afore sending email. Cause you may face error.
In this tutorial, i am going to tell you how to send email using gmail smtp server configuration using laravel 7 mailable class. It is very easy to make and best way. you have to just follow few step and you will get simple mail send example in your laravel 7 application.
In this tutorial i am using mailtrap fake email testing system. Let's start our laravel 7 email sending tutorial.
Open mailtrap.io in your browser and create an account. Here we need user id and user email to send email.
Now having done this you will get below information. You have to put these credentials into your .env file.
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME= //username from your mailtrap credentials.
MAIL_PASSWORD= //password from your mailtrap credentials.
MAIL_ENCRYPTION=null
Now we have to create our email sending class to send email in laravel 7. Run below command to create it.
php artisan make:mail NewMail
after running this command you will find this in the following directory like app/Mail/NewMail.php. Now paste this below code in this NewMail file.
app/Mail/NewMail.php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class NewMail extends Mailable{
use Queueable, SerializesModels;
public $user;
public function __construct($user){
$this->user = $user;
}
public function build(){
return $this->subject('This is Testing Mail')
->view('email.test');
}
}
After doing above things In this step, we have to find resources/views and create a new folder name email & create a new file test.blade.php and put the below code.
resources/views/email/test.blade.php
<!DOCTYPE html>
<html>
<head>
<title>This Email generated by www.codechief.org</title>
</head>
<body>
<h1>{{ $user['name'] }}</h1>
<p>{{ $user['info'] }}</p>
<p>Thank you</p>
</body>
</html>
We are in the last step in our tutorial. So create a route to send email in laravel 7 application. Paste this bbelow code to web.php.
routes/web.php
Route::get('test', function () {
$user = [
'name' => 'Harsukh Makwana',
'info' => 'Laravel & Python Devloper'
];
\Mail::to('[email protected]')->send(new \App\Mail\NewMail($user));
dd("success");
});
Now time to check this laravel email sending tutorial, Open below url to your browser and check.
http://127.0.0.1:8000/test
i hope you like this article.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to Upload Multiple Files & Images in PHP 7 with MySql Example
In this tutorial, we will learn how to u...Laravel Dynamically Add or Remove Input Fields jQuery
In this article, we will share with you...How to Split a String into an Array of Characters in JavaScript
Use the split() Method The JavaScript...HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
in this article, I will share with you h...How to create jQuery slide left and right toggle effect
Use the jQuery animate() metho...