How To Send Email With Attachment In Laravel 9

Websolutionstuff | Mar-16-2022 | Categories : Laravel PHP

In this article, we will see how to send email with attachments in laravel 9. As we all know mail functionalities are common in all project but if you want to send mail with attechment in some cases then this post is for you here we will see how to attach file in mail in laravel 9.

So, let's see send email with attachment in laravel 9, how to send attachment in mail using laravel 9, send pdf attachment in mail laravel 9, laravel 9 send email with attachment

Step 1 : Set Configuration for sending email

Step 2 : Add Route

Step 3 : Add Controller

Step 4 : Create Blade File


Step 1 : Set Configuration for sending email

First of all we need to add send email configuration with mail driver, mail host, mail port, mail username, mail password etc in your .env file

MAIL_USERNAME=Your user name



Step 2 : Add Route

Now, add route in your routes/web.php file.

Route::get('send/mail', [SendMailController::class, 'send_mail'])->name('send_mail');


Step 3 : Add Controller

Now create SendMailController and copy the below code in your controller.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Mail;

class SendMailController extends Controller
    public function send_mail(Request $request)
        $data["email"] = "[email protected]";
        $data["title"] = "";
        $data["body"] = "This is test mail with attachment";
        $files = [
        Mail::send('mail.Test_mail', $data, function($message)use($data, $files) {
            foreach ($files as $file){

        echo "Mail send successfully !!";



Step 4 : Create Blade File

Now, create a blade file in this file location resources\views\mail\Test_mail.blade.php for display messages in the mail

Hi, Websolutionstuff <br/>
This is Test Mail.<br />
Thank you...!!

Output :



You might also like :

Recommended Post
Featured Post
How To Add Ckeditor In Laravel
How To Add Ckeditor In Laravel

In this article, I will explain you how to add ckeditor in laravel, CKEditor is a WYSIWYG rich text edito...

Read More


StartOf And EndOf Functions Example Of Carbon
StartOf And EndOf Functions Ex...

In this article, we will see startof and endof functions example of carbon in laravel. As you all know carbon provide ma...

Read More


Laravel 8 One To Many Polymorphic Relationship
Laravel 8 One To Many Polymorp...

In this tutorial we will learn about laravel 8 one to many polymorphic relationship. A one-to-many polymorphic rela...

Read More


How To Add Foreign Key In Laravel 10 Migration
How To Add Foreign Key In Lara...

In this article, we will see how to add a foreign key in laravel 10 migration. Here, we will learn about laravel 10...

Read More