How To Send Email In Laravel 9 Using Mailtrap

Step 1: Create a Mailtrap AccountStep 2: Setup .env file ConfigurationStep 3: Create Mailable ClassStep 4: Create Blade FileStep 5: Create Route
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
php artisan make:mail TestMail
<? phpnamespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class TestMail 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('emails.test');
}
}
<!DOCTYPE html>
<html>
<head>
<title>How To Send Email In Laravel 9 Using Mailtrap - Websolutionstuff</title>
</head>
<body>
<h5>{{ $user['name'] }}</h5>
<p>{{ $user['info'] }}</p>
<p>Thank you</p>
</body>
</html>
Route::get('send-mail', function () {    $user = [
'name' => 'Websolutionstuff',
'info' => 'This is mailstrap example in laravel 9'
];
\Mail::to('test@example.com')->send(new \App\Mail\TestMail($user)); dd("Successfully send mail..!!");});

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Websolutionstuff

Websolutionstuff

96 Followers

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API.