Posted inLaravel / Mysql / php

laravel attachment – Laravel Send Email with Multiple Attachment Example

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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype