laravel attachment with Send Email with Multiple Attachment is always cumbersome work in web application. Laravel provides a very simple api to send mail to users.
laravel attachment
Laravel latest version of the file attachment helpers. Today in this article We are going to show you how to send mail with laravel attachment.
Step 1: Install Laravel
composer create-project --prefer-dist laravel/laravel sendEmailExample
Step 2: Make Configuration
.env
MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 [email protected] MAIL_PASSWORD=rrnnucvnqlbsl MAIL_ENCRYPTION=tls [email protected] MAIL_FROM_NAME="${APP_NAME}"
Don’t miss : Unique Collection – Laravel Collection Get Unique Values Example
Step 3: Create Mail
In this phase i will make mail class SendDemoEmailExample for email sending.
php artisan make:mail SendDemoEmailExample
app/Mail/SendDemoEmailExample.php
information_data = $information_data; } /** * Build the message. * created by Pakainfo.com * @return $this */ public function build() { $this->subject('Mail from pakainfo.com') ->view('emails.SendDemoEmailExample'); foreach ($this->information_data['files'] as $file){ $this->attach($file); } return $this; } }
Step 4: Create Blade View
resources/views/emails/SendDemoEmailExample.blade.php
pakainfo.com {{ $information_data['title'] }}
{{ $information_data['body'] }}
Thank you
Step 5: Add Route
routes/web.php
Step 6: Add Controller
app/Http/Controllers/EmailController.php
'Mail from pakainfo.com 2', 'body' => 'Demo Example: This pakainfo is for testing email using smtp', 'files' => $files ]; Mail::to('[email protected]')->send(new SendDemoEmailExample($information_data)); dd("Email is Sent."); } }I hope you get an idea about laravel attachment.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.