How to Send Mail with PDF Attachment in Laravel

Hello artisan,

This amazing example tutorial will guide you laravel mail send with pdf attachment. We can see laravel email send with pdf attachment from this example. This example will teach you laravel mail attachment pdf. I will explain simple way of laravel send mail with pdf attachment.

You know that you can send emails with attachments in laravel 6, laravel 7, laravel 8 and laravel 9 applications with this source code. In this example, I will simply add files as attachments with sending emails in this example. If you want learn this then you just need to follow a few steps to create a simple example of sending 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 a fresh Laravel application using the bellow command, So open your terminal OR command prompt and run the bellow command:

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


Step 2: Make Configuration

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




Read also: Laravel 9  Activate Account after Email Verification Example


Step 3: Create Route

In this step, we need to create routes for an item listing. so open your "routes/web.php" file and add the 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 a new controller PDFController that will manage generate pdf method of the route. make sure you have a "files" folder in public with the 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

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



Read also: How to Add cc and bcc in Laravel Mail


Hope it can help you.


Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js