How to set dynamic SMTP details laravel

后端 未结 2 1885
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-22 10:52

I am working with a project where i need to update SMTP details on every admin login. I am storing the details in database, what is the best way to do that.

2条回答
  •  广开言路
    2021-01-22 10:57

    My own approach: remove Illuminate\Mail\MailServiceProvider::class from config/app.php list of providers loaded at bootstrap, and create a new middleware to load it manually after the user has been identified.

    auth = $auth;
        }
    
        public function handle($request, Closure $next)
        {
            /*
                $conf is an array containing the mail configuration,
                a described in config/mail.php. Something like:
    
                [
                    'driver' => 'smtp',
                    'host' => 'smtp.mydomain.com',
                    'username' => foo',
                    'password' => 'bar'
                    ...
                ]
            */
            $conf = my_own_function();
    
            Config::set('mail', $conf);
    
            $app = App::getInstance();
            $app->register('Illuminate\Mail\MailServiceProvider');
    
            return $next($request);
        }
    }
    

    Source: http://blog.madbob.org/laravel-dynamic-mail-configuration/

提交回复
热议问题