How To Send Email Using Markdown Mailable Laravel 9

composer create-project laravel/laravel email-example
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=mail_from@gmail.com
MAIL_FROM_NAME="${APP_NAME}"
php artisan make:mail MarkdownSendMail --markdown=emails.markdownDemoMail
<? phpnamespace App\Mail;

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

class MarkdownSendMail extends Mailable{
use Queueable, SerializesModels; public $user; public function __construct($user){ $this->user = $user; } public function build(){ return $this->subject('This is markdown mail example')
->markdown('emails.markdownDemoMail');
}
}
php artisan make:controller SendMailController
<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;
use App\Mail\SendMail;
use Mail;
class SendMailController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$user = [
'name' => 'Websolutionstuff',
'info' => 'https://websolutionstuff.com/'
];
\Mail::to('test@example.com')->send(new MarkdownSendMail($user)); dd("Successfully send mail..!!"); }
}
@component('mail::message')
# {{ $mailData['title'] }}

The body of your message.

@component('mail::button', ['url' => $mailData['info']])
Visit Our Website
@endcomponent

Thanks,
{{ config('app.name') }}
@endcomponent
<?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\SendMailController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('send-mail', [SendMailController::class, 'index']);

--

--

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.