Skip to content

All topics  /  Laravel

How To Send Markdown Link Mail In Laravel?

Laravel

Teams applying “How To Send Markdown Link Mail In Laravel?” in a production project can use the linked project resource to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.

Before copying the example into a live application, confirm version-specific behaviour with the official Laravel website and test it against the project’s actual database and runtime.

Jan 03, 2022

Hi Friends,

This article will give you example of send marokdown link mail in laravel. I explained simply about send marokdown link mail larael. This tutorial will give you simple example of laravel marokdown link mail.you'll learn link mail marokdown laravel.

In this post, i will show you how to laravel markdown email send link laravel 8 , laravel 7 and laravel 6.

This tutorial will teach you with profoundness about how to easily send uncomplicated email using GMAIL SMPT settings within the framework of Laravel. And yes we will lay the foundation with Laravel 8 mailable class.

Laravel Markdown provides components, tables, email link and button. Markdown beautiful layout you can use with email template.

so let's see bellow solution:

Step 1 - Set Mail Configuration


You have to add your gmail smtp configuration, open your .env file and add your configration.

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls

Step 2 - Create Mailable Class with Markdown

php artisan make:mail SendEmailLink --markdown=emails.sendEmailLink

app/Mail/SendEmailLink.php

<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class SendEmailLink extends Mailable
{
    use Queueable, SerializesModels;
    public $maildata;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($maildata)
    {
        $this->maildata = $maildata;
    }
    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('emails.sendEmailLink')->with('maildata', $this->maildata);
    }
}

Step 3 - Add Route

routes/web.php

<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\MailController;
Route::get('send-mail', [MailController::class, 'sendMail']);
Route::get('send-mail-link', [MailController::class, 'sendMailLink'])->name('send-mail-link');

Step 4 - Create Controller

php artisan make:controller MailController

app/Http/Controllers/MailController.php

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Mail\SendEmailTest;
use Mail;
class MailController extends Controller
{	
     /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
    */
    public function sendMail()
    {
        $email = '[email protected]';

   
        $maildata = [
            'title' => 'Laravel Mail Markdown Link',
        ];

  
        Mail::to($email)->send(new SendEmailLik($maildata));

   
        dd("Mail has been sent successfully");
    }
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
    */
    public function sendMailLink()
    {
        dd('Nicesnippets.com');       
    }
}

Step 5 - Add View File

resources/views/emails/sendMailLink.blade.php

@component('mail::message')
# {{ $maildata['title'] }}
Hello Dev.
@component('mail::button', ['url' => route('send-mail-link')])
Verify
@endcomponent
Thanks,
{{ config('app.name') }}
@endcomponent

You can run your project by using following command:

php artisan serve

Now open this url:

http://localhost:8000/send-mail

Output:

It will help you...