Send a Mail With Laravel

Mail sending process should be clean and simple as much as possible. Laravel Provide a elegant way to send email with SwiftMailer library. Here we will give two example where we can use our custom layout and Laravel Email Layout. Let’s start

Send a Mail With Laravel

Before we start process we need to set some configuration that Laravel will use to send email so you can check your .env file where you will see some variable that have Identical name MAIL_ prefix. For Testing Purpose we will use credential while development.

Plain TextCopy
MAIL_USERNAME=< username>
MAIL_PASSWORD=< password>

just change < username> or < password> with your own username or password that you get from after signUp.

After setup credential to .env just run below command to make mail File from mailable.

php artisan make:mail SendNewMail --markdown=emails.new_mail

This command will do two things.

  1. Create a Class File in App\Mail directory (Also make Directory if no exist before)
  2. Create View file that you added after –markdown= (before . text will convert into folder)

Now let check out SendNewMail.php from App\Mail folder.



namespace App\Mail;

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

class SendNewMail extends Mailable
    use Queueable, SerializesModels;

     * Create a new message instance.
     * @return void
    public function __construct()

     * Build the message.
     * @return $this
    public function build()
        return $this->markdown('emails.new_mail');

This is simple class that responsible to clean code.

Basic to Advance Routing in Laravel

now take a look to new_mail.blade.php that available resources/views/emails folder.


# Laravel Test

This is New Email

    This is the panel content.

    | Laravel       | Table         | Example  |
    | ------------- |:-------------:| --------:|
    | Col 2 is      | Centered      | $10      |
    | Col 3 is      | Right-Aligned | $20      |

@component('mail::button', ['url' => ''])
    Button Text

{{ config('') }}

This is simple markdown mail template that you can edit as per your requirement.

now lets check how we send mail.


use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    \Illuminate\Support\Facades\Mail::to('[email protected]')
            ->send(new \App\Mail\SendNewMail());
           ->send(new \App\Mail\SendNewMail());

now just visit root url of your app and check your mailtrap demo inbox.


You checked that sending mail is very easy then we think. If you ever stuck to sending email just comment below and i will answer your comment with solution. Till that Keep Coding Stay Happy

Leave a Reply

Your email address will not be published. Required fields are marked *