How To Send Email With File Attachment In Laravel- 8 ?




How To Send Email With File Attachment In Laravel- 8 ?

Hi guys,

Today i will today i will explained to the how to send email with file attachment in laravel- 8 project.How to send email with file attachment in laravel- 8 is so easy to use.So you can just follow my step by step and learn how to send email with file attachment in laravel- 8.

We will use how to send attachment in mail using laravel.You can see how to attach file in mail in laravel and implement a send attachment in mail in laravel.

We can send email with attachment in laravel 6, laravel 7 and laravel 8 application. and send email with add file as attechment with sending mail in just follow for a my few step to create a sending mail with attechment.

So let's start to the example.

Step 1: Install a New Project

First step to create a new project in just following command through.

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

Step 2 :.Env

Next step to your project .env file to add the mail configration in your project and configure your project.






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\SendMailController;



| 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-file-attecment', [SendMailController::class, 'index']);

Step 4: Add new SendMailController

Next step to you can create a new SendMailController in your current laravel 8 project.

So let's put bellow code.



namespace App\Http\Controllers;

use PDF;

use Mail;

class SendMailController extends Controller



* Write code on Method


* @return response()


public function index()


$data["email"] = "";

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

$data["body"] = "This is Demo Mail Attechment Pdf File";

$attechfiles = [




Mail::send('emails.fileAttechmemtMail', $data, function($message)use($data, $attechfiles) {

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


foreach ($attechfiles as $file){




dd('Mail sent successfully Check Send Mail Email Address.');



Step 5: Add View File

Finally last step to you can create a blade file in fileAttechmemtMail.blade.php(resources/views/emails/fileAttechmemtMail.blade.php) for a layout file and use the code.


<!DOCTYPE html<






<h1>File Attechment Mail,</h1>

<p>This Is File Attechment Mail Example,</p>

<p>Thank You.</p>



So, finally now you can run the code in check the example

php artisan serve


It will help you...


#Laravel 8

#Laravel 7


#Laravel 6