Home » How to Send Emails in Laravel?

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.

Read Also:  How To Print Last Query In PHP?

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,<br>
{{ 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.

Read Also:  Laravel 6 Get All query string parameters

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Add Edit And Delete Records Using jQuery Ajax PHP And MySQL
  2. Read Also:  Laravel Create Custom Helper Class Example
  3. Read Also:  Group By with Sum using Laravel Collection
  4. Read Also:  PHP MySQL Inline Editing Dynamically using jQuery Ajax
  5. Read Also:  Laravel 5/6/7 CRUD Operations Example Step By Step
  6. Read Also:  Laravel sending email via gmail smtp server Setup configuration
  7. Read Also:  set operations sql
  8. Read Also:  PHP Laravel 7 Send Email Example Tutorial
  9. Read Also:  PHP download file from URL Curl
  10. Read Also:  Dependent dropdown example in PHP MySQL

Leave a Comment

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