How to Send Email with Attachment in Laravel?

By Hardik Savani November 5, 2023 Category : Laravel

This post will give you example of how to send email with attachment in laravel. We will use how to send attachment in mail using laravel. you can see how to attach file in mail in laravel. In this article, we will implement a send attachment in mail in laravel. Alright, let’s dive into the steps.

we can send email with attachment in laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 application.

In this example, i will simply add files as attachment with sending email. you just need to follow few step to create simple example of send mail with files in laravel app.

Let's see bellow steps:

Step 1: Install Laravel

I am going to explain step by step from scratch so, we need to get fresh Laravel application using bellow command, So open your terminal OR command prompt and run bellow command:

composer create-project --prefer-dist laravel/laravel blog

Step 2: Make Configuration

In first step, you have to add send mail configuration with mail driver, mail host, mail port, mail username, mail password so laravel will use those sender details on email. So you can simply add as like following.







Step 3: Add Route

In this is step we need to create routes for items listing. so open your "routes/web.php" file and add following route.



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\PDFController;



| Web Routes



| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!



Route::get('send-email-pdf', [PDFController::class, 'index']);

Step 4: Add Controller

Here,we require to create new controller PDFController that will manage generatePDF method of route.

make sure you have "files" folder in public with following files.

So let's put bellow code.



namespace App\Http\Controllers;

use PDF;

use Mail;

class PDFController extends Controller



* Write code on Method


* @return response()


public function index()


$data["email"] = "";

$data["title"] = "From";

$data["body"] = "This is Demo";

$files = [




Mail::send('emails.myTestMail', $data, function($message)use($data, $files) {

$message->to($data["email"], $data["email"])


foreach ($files as $file){




dd('Mail sent successfully');



Step 5: Create View File

In Last step, let's create myTestMail.blade.php(resources/views/emails/myTestMail.blade.php) for layout of pdf file and put following code:


<!DOCTYPE html>






<h1>{{ $title }}</h1>

<p>{{ $body }}</p>

<p>Thank you</p>



Now you can run and check example.

It will send you email, let' see.

Run Project:

php artisan serve

Open Link:



I hope it can help you...

Tags :