Hi coders. In this tutorial, i’ll show you how to send email with attachment using Mailable class in laravel . You can simply send file in mail by using the attach() method.

In this example, i will simply add files as attachment with sending email. Let’s dive in.

 

1- Mail Configuration

First thing to do is to configure your SMTP in .env file.

2- Create Mailable Class

Next, you have to execute the make:mail command in your composer.

Now you can find new file in “app/Mail/TestMail.php” folder.

Make sure you have to add “example.pdf” file public folder.

3- Add Route

Now we need to create route to send mail. Open your “routes/web.php” file and add following route.

Read Also  How to build Multiple Authentication in Laravel

4- Add Controller

To add controller execute the following command.

Edit controller file in app/Http/Controllers/TestMailController.php

5- Add View File

Last, we need to create email template view file in “resources/views/emails/testMail.blade.php” and put the following code :

 

Now you can run and check example.

I hope it can help you :).


No Comments

Leave a Reply

your email address will not be published. required fields are marked *

*
*