我正在使用 Laravel 5.1
我创建了一个函数来从数据库中获取用户 $mail_config=STMPDetails::where('user_id',36)->first()
的 smtp 信息,然后我可以调用 >config
辅助函数并传递数组以设置配置值 config($mail_config)
。然后调用 Mail::queue
函数。
但在到达 createSmtpDriver@vendor/laravel/framework/src/Illuminate/Mail/TransportManager.php
之前,它再次读取配置以发送邮件,邮件配置更改为指定的配置在 .env 文件中。
另外需要注意的是Mail发送功能在Listener中
我不知道在哪里可以调用该函数,以便在发送邮件之前保留配置更改。
谢谢, K
最佳答案
这应该有效:
// Set your new config
Config::set('mail.driver', $driver);
Config::set('mail.from', ['address' => $address, 'name' => $name]);
// Re execute the MailServiceProvider that should use your new config
(new Illuminate\Mail\MailServiceProvider(app()))->register();
关于php - 在运行时为用户更新配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41678610/