Add laravel mail to your composer.json file
To add Laravel Mail to your composer.json
file, you can follow these steps:
-
Open your
composer.json
file in a text editor. -
Add the following line under the
require
section:"illuminate/mail": "^8.0"
This will add the Laravel Mail package to your project's dependencies.
-
Save the changes to your
composer.json
file. -
Run the following command in your terminal to update your project's dependencies:
composer update
This will download and install the Laravel Mail package and its dependencies.
-
Once the installation is complete, you can use the Laravel Mail facade in your Laravel application.
Here's an example of how you can use the Laravel Mail facade:
use Illuminate\Support\Facades\Mail;
Mail::send('emails.welcome', ['user' => $user], function ($message) {
$message->from('[email protected]', 'Hello');
$message->to('[email protected]', 'User');
$message->subject('Welcome!');
});
In this example, we're sending a welcome email to the user using the Mail::send
method. The first argument is the view name, the second argument is an array of data to pass to the view, and the third argument is a closure that defines the email message.
Note: Make sure you have the emails
directory in your Laravel project's root directory, and that you have created a welcome.blade.php
view in that directory.