Laravel 8 Send Email With File Attachment
Hello Dev,
At the moment, i we’ll present you laravel eight ship e-mail with file attachment. This text will provide you with easy instance of laravel eight ship e-mail with file attachment. you’ll laravel eight ship e-mail with file attachment. On this article, we’ll implement a laravel eight ship e-mail with file attachment.
We are going to use the way in which to ship attachment in mail victimisation laravel.You may see the way in which to connect get in mail in laravel and implement a ship attachment in mail in laravel.
We are able to ship e-mail with attachment in laravel vi, laravel seven and laravel eight utility. and ship e-mail with add file as attechment with causation mail in precisely comply with for a my few step to kind a causation mail with attechment.
So let’s comply with few step to create instance of laravel eight ship e-mail with file attachment.
Step 1: Set up a New Laravel
composer create-project --prefer-dist laravel/laravel weblog
Step 2: .Env
MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 mail_username=google@gmail.com MAIL_PASSWORD=123456789 MAIL_ENCRYPTION=tls mail_from_address=google@gmail.com MAIL_FROM_NAME="${APP_NAME}"
Step 3: Add Route
routes/internet.php
<?php use IlluminateSupportFacadesRoute; use AppHttpControllersSendMailController; Route::get('send-email-file-attecment', [SendMailController::class, 'index']);
Step 4: Add new SendMailController
app/Http/Controllers/SendMailController.php
<?php namespace AppHttpControllers; use PDF; use Mail; class SendMailController extends Controller { /** * Write code on Methodology * * @return response() */ public operate index() { $information["email"] = "xyz@gmail.com"; $information["title"] = "From Nicesnippest.com"; $information["body"] = "That is Demo Mail Attechment Pdf File"; $attechfiles = [ public_path('file/test1.pdf'), public_path('file/test2.pdf'), ]; Mail::ship('emails.fileAttechmemtMail', $information, operate($message)use($information, $attechfiles) { $message->to($information["email"], $information["email"]) ->topic($information["title"]); foreach ($attechfiles as $file){ $message->connect($file); } }); dd('Mail despatched efficiently Examine Ship Mail Electronic mail Tackle.'); } }
Step 5: Add View File
assets/views/emails/fileAttechmemtMail.blade.php
<!DOCTYPE html> <html> <head> <title>Nicesnippets.com</title> </head> <physique> <h1>File Attechment Mail,</h1> <p>This Is File Attechment Mail Instance,</p> <p>Thank You.</p> </physique> </html>
Run
php artisan serve
I hope it is going to help you…
Komentar
Posting Komentar