How to call configure mail array in laravel in controller

In Laravel, you can configure the mail array in your controller by using the Mail::configure() method. Here's an example:

use Illuminate\Support\Facades\Mail;

public function sendMail()
{
    Mail::configure([
        'driver' => 'smtp',
        'host' => 'smtp.example.com',
        'port' => 587,
        'username' => '[email protected]',
        'password' => 'your-password',
        'encryption' => 'tls',
        'timeout' => 10,
    ]);

    // Now you can use the Mail facade to send emails
    Mail::send('emails.your-email', [], function($message) {
        $message->to('[email protected]', 'Recipient Name');
        $message->subject('Test Email');
    });
}

In this example, we're configuring the mail array to use the SMTP driver, with the specified host, port, username, password, encryption, and timeout.

You can also configure the mail array in the config/mail.php file, which is the recommended way to do it. This file is located in the config directory of your Laravel project.

Once you've configured the mail array, you can use the Mail facade to send emails in your controller.

Alternatively, you can use the config/mail.php file to configure the mail array and then use the Mail facade to send emails. Here's an example:

use Illuminate\Support\Facades\Mail;

public function sendMail()
{
    // Get the mail configuration from the config file
    $config = config('mail');

    // Use the Mail facade to send emails
    Mail::send('emails.your-email', [], function($message) use ($config) {
        $message->to($config['from']['address'], $config['from']['name']);
        $message->subject($config['subject']);
    });
}

In this example, we're getting the mail configuration from the config/mail.php file and then using it to send an email using the Mail facade.