
Laravel 9 e-mail sending tutorail; on this tutorial we can learn how to send emails in laravel 9 the usage of SMTP drivers like Mailgun, Postmark, Amazon SES and sendemail.
Laravel 9 provide us a mail class for sending emails. So we would really like to show you the way to send emails from localhost the use of mailable in laravel 9 project.
Laravel 9 affords numerous SMTP drivers consisting of Mailgun, Postmark, Amazon SES and sendmail.
This is a simple way to send multiple emails from localhost. It also work on live server.
Following steps are required to send emails from localhost in laravel 9 project:
Step 1 – Laravel 9 App creating
Step 2 – SMTP Configuration in .env file
Step 3 – Mailable Class creating
Step 4 – Email Send Route creating
Step 5 – View files creating
Step 6 – Email Controller creating
Step 7 – Testing project
First of all we need a fresh project of laravel 9. run the given comman to create a new project:
composer create-project laravel/laravel EmailSend
Open your project on your favourite code editor and open file .env and replace the given code.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=enter your email which you want to use for mail sent
MAIL_PASSWORD=enter password of email which you using
MAIL_ENCRYPTION=tls
If you using Gmail to send a mail then you need to turn of Less Secure in google account setting. Click here to update your setting.
We need a NotifyMail class which is creating by running given command.
Php artisan make:mail NotifyMail
After creating NotifyMail update with the given code or you can simply write in build() function:
return $this>view('MailSend');
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NotifyMail extends Mailable
{
use Queueable, SerializesModels;
public function __construct()
{
//
}
public function build()
{
return $this>view('MailSend');
}
}
In your project directory open routes/web.php file and paste the given code in it.
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\EmailController;
Route::get('emailsend', [EmailController::class, 'index']);
So in this we will see how to create view files which are use to send mail. Open resouces/views directory then create a files with name MailSend.blade.php and paste given code in it and save.
<!DOCTYPE html>
<html>
<head>
<title>How to Send Email in Laravel 9</title>
</head>
<body>
<h2>TheSkillStock – Email Sending Testing</h2>
<p>How to Send Email in Laravel 9</p>
</body>
</html>
So the main step in this tutorial is a EmailController which provide functionality to send email to a user. Run the given command to create controller:
php artisan make:controller EmailController
So in your project directory open App/Http/controllers and open EmailController.php and replace with the given code.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mail;
use App\Mail\NotifyMail;
class EmailController extends Controller
{
public function index()
{
Mail::to('ReciverEmail')->send(new NotifyMail());//replace and email which going to recive a email with ReciverEmail
if (Mail::failures()) {
return response()->Fail('Sorry! Please try again latter');
}else{
return response()->success('Successfully send your mail');
}
}
}
So the final step is to test our project by running this command.
php artisan serve
Click here to open your project:
Run project http://127.0.0.1:8000/
Thank You For reading this tutorial
<a href="https://european-sailing.com/rent-yachts-italy">sailing charter italy | european yachts</a>
yacht charter italien <a href="https://eurosegeln.com/yachtcharter-italien">go now</a>
<a href="https://piterskie-zametki.ru/222881">Любовь Толкалина хейтерам «всё, чем вы недовольны — плод вашего видения мира и разума» - срочно</a>
<a href="https://gurava.ru/geocities/39/%D0%91%D0%BE%D1%80%D0%B7%D1%8F">недвижимость Борзя сайт Гурава</a>
<a href="https://www.kolmovo.ru/CAT1/1.html">найти работу в великом новгороде свежие вакансии</a>
<a href="https://hills-pet-food.com/hills-prescription-diet-digestive-care-i-d-stress-chicken-formula/">Hill's Prescription Diet Digestive Care i/d Stress Chicken Formula Dry Dog Food</a>
Between us speaking. _ _ _ _ _ _ _ _ _ _ _ <a href=https://sale-time.com/iherb/>iherb promotion</a>
virtual local numbers Mar 18th 2023
virtual phone number in <a href="https://virtual-local-numbers.com/countries/27-portugal.html">portugal</a>