How to Send Emails in Laravel?

Today, We want to share with you send email laravel.In this post we will show you laravel smtp mail, hear for email laravel using gmail we will give you demo and example for implement.In this post, we will learn about Simple Laravel Sending Emails Example with an example.

Laravel Mail – Sending Mailable, Markdown Mailable, and Raw HTML

There are the Following The simple About send email laravel mailtrap Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel send mail from localhost, so the laravel send mail without smtp is used for this example is following below.

Laravel Mail with Mailable

php artisan make:mail SampleEmail

SampleEmail.php at app/Mail

namespace App\Mail;

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

class SampleEmail 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->view('view.name');
    }
}

add the subject part, HTML view, from or attachment bellow Source Code
resources/views/emails/sample_email.blade.php

....

use Queueable, SerializesModels;

public $subject;

public $data;

/**
 * Create a new message instance.
 *
 * @param string $subject Email Subject
 * @param mixed $data    Template data
 *
 * @return void
 */
public function __construct($subject, $data)
{
    $this->subject = $subject;
    $this->data    = $data;
}


public function build()
{
    return $this->subject($this->subject)
        ->view('emails.sample_email', [
            'data' => $this->data
        ]);
}

....

send email laravel using Laravel

$subject       = 'Welcome to Laravel Mailable';
$receiverEmail = '[email protected]';
$receiverData  = \App\User::where('email', $receiverEmail)->first();

Mail::to($receiverEmail)->send(new \App\Mails\SampleEmail($subject, $receiverData));

Laravel Mail with Markdown Mailable

php artisan make:mail SampleMarkdownEmail --markdown=emails.sample_markdown_email

template Code

@component('mail::message')
# Introduction

The body of your message.

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

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

SimpleMarkdownEmail To send Mail

public function build()
{
    return $this->markdown('emails.sample_markdown_email');
}

Laravel Mail with Raw HTML

Mail::send([], [], function($message) use ($data) {
    $message->from($data['from']);
    $message->to($data['to']);
    $message->subject($data['subject']);
    $message->setBody($data['content'], 'text/html');
});

Summary

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

I hope you get an idea about send email laravel.
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.

Leave a Comment