Join WhatsApp ChannelJoin Now

Laravel 10 E-Mail Send With Attachment

Hi dev,

Today, i show you laravel 10 E-Mail send with attachment. This article will give you simple example of laravel 10 E-Mail send with attachment. you will laravel 10 E-Mail send with attachment. In this article, we will implement a laravel 10 E-Mail send with attachment.

So, let’s follow few steps to create example of laravel 10 E-Mail send with attachment.

Step 1: Laravel 10 Install

Follow This Command And Install Laravel

composer create-project laravel/laravel example-email

Step 2: Install Package & Config

First, we need to install barryvdh/laravel-dompdf package. Run this composer command to install the package:

composer require barryvdh/laravel-dompdf

Now open the .env file and set your SMTP credentials:


Step 3: Add Route



use App\Http\Controllers\TestController;
use Illuminate\Support\Facades\Route;

| 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', [TestController::class, 'sendMailWithPDF']);

Step 4: Add Controller



namespace App\Http\Controllers;

use PDF;
use Mail;

class TestController extends Controller
     * Write code on Method
     * @return response()
    public function sendMailWithPDF()
        $data["email"] = "";
        $data["title"] = "Welcome to";
        $data["body"] = "This is the email body.";

        $pdf = PDF::loadView('mail', $data);

        Mail::send('mail', $data, function ($message) use ($data, $pdf) {
            $message->to($data["email"], $data["email"])
                ->attachData($pdf->output(), "test.pdf");

        dd('Email has been sent successfully');

Step 5: Add PDF Blade File


<!DOCTYPE html>
    <title>Laravel 10 E-Mail Send With Attachment -</title>
    <h3>{{ $title }}</h3>
    <p>{{ $body }}</p>


Step 6: Run Laravel:

php artisan serve

Now, you have to open the web browser, type the given URL and view the app output:


I hope it will assist you…

Recommended Posts