Laravel Send Markdown Link Mail Example


Share:
 | Published By: Admin | Published On: Jan 03, 2022 | Category: Laravel 8 Laravel


Hello Dev,

Now let's see example of how to send markdown link mail example. This is a short guide on send markdown link mail in laravel. We will check how to send markdown link mail. Let's get started with how to send markdown link mail in laravel.

Here i will give you many example how to send markdown link mail using laravel.

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 = 'aatmaninfotech@gmail.com';
   
        $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...

Share: