Support the ongoing development of Laravel.io →
Configuration Database

`In my Laravel application, I am trying to send mail notification based on the company_id of the logged in user:

I have this:

$mail=DB::table('mail_settings')->first();
$config = array(
           'driver' => $mail->driver,
           'host' => $mail->host,
           'port' => $mail->port,
           'from' => array('address' => $mail->from_address, 'name' => $mail->from_name),
           'encryption' => $mail->encryption,
           'username' => $mail->username,
           'password' => $mail->password,
           'sendmail' => '/usr/sbin/sendmail -bs',
           'pretend' => false
       );
Config::set('mail',$config);

Models

class Company extends Model
{
   protected $table = 'companies';
   protected $fillable = [
    'id',
    'organization_name'
  ];
}

class User extends Authenticatable
{
   protected $fillable = [
    'name',
    'company_id',
    'email',
 ];
}

Is there any way to override default mail configuration (in app/config/mail.php) on-the-fly (e.g. configuration is stored in database) before mailer transport is created?

Thanks

Is there any way to recreate laravel swiftmailer transport so it can pick up updated config values?`

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Michael noblemfd Joined 28 Mar 2019

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.