Send Emails Using Laravel 6 Mailable Class?

Today, We want to share with you How To Send Emails Using Laravel 6 Mailable Class.In this post we will show you Laravel 6 Sending Emails Tutorial Example, hear for Send Email with Laravel 6 using Markdown Mailable Class we will give you demo and example for implement.In this post, we will learn about Sending Email, send email, send email in laravel 6, mail() Function with an example.

How To Send Emails Using Laravel 6 Mailable Class

There are the Following The simple About how to send email in laravel 6 example Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to Send Mail using smtp in Laravel 6?, so the How To Laravel 6 Send Email Tutorial And Example is used for this example is following below.

Laravel 6 Supports an API with driver support for SMTP, PHP Laravel 6 SendMail, using Mailgun, using Sendgrid, Mandrill, using Amazon SES, SpartPost, or More.

Step 1: Change Simple Send Mail Configuration

.env

add send Email configuration with mail driver, mail host Name, mail port, mail username, mail security password

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=example@gmail.com
MAIL_PASSWORD=Example#4549865
MAIL_ENCRYPTION=tls

Step 2: Create Mail

php artisan make:mail SendMail

app/Mail/SendMail.php

<?php
  
namespace App\Mail;
   
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
  
class SendMail extends Mailable
{
    use Queueable, SerializesModels;
  
    public $userInfo;
   
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($userInfo)
    {
        $this->userInfo = $userInfo;
    }
   
    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->subject('Good Latest Testing for Mail from tamilRokersDemo.com')
                    ->view('emails.sendEmail');
    }
}

Step 3: Create Blade View

resources/views/emails/sendEmail.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>tamilRokersDemo.com</title>
</head>
<body>
    <h1>{{ $userInfo['title'] }}</h1>
    <p>{{ $userInfo['body'] }}</p>
   
     <p>Thank you, {{ $userInfo->user_name }}</p>
</body>
</html>

Step 4: Define a Laravel 6 Route

routes/web.php

Route::get('sendmail', function () {
   
    $userInfo = [
        'title' => 'PHP Laravel 6 Send Email Example - for Testing Purpose',
        'body' => 'This is a email demo from TamilRokers jio 2020 to 2025',
        'user_name' => 'Virat Kohali'
    ];
   
    \Mail::to('[email protected]')->send(new \App\Mail\SendMail($userInfo));
   
    Session::flash('success', trans('messages.MailSendSuccess'));
    return redirect('mail');
});

Web Programming Tutorials Example with Demo

Read :

Also Read This ๐Ÿ‘‰   php remove newline - How to remove newlines (characters) from a string in php?

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel 6 send mail example smtp.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโ€™t forget to share.