无法在Laravel中使用动态邮件配置

问题描述

我想覆盖laravel认使用的config / mail.PHP或.env中的邮件设置。我正在设置动态配置(来自数据库),但是发送时的电子邮件仍然来自config / mail.PHP或.env中设置的“发件人”地址。

对以上词语有何建议?

这是我使用的代码的一部分:

$mailConfigs = [
    'driver' => 'smtp','port' => $dbSettings->smtp_port,'host' => $dbSettings->smtp_host,'encryption' => $dbSettings->smtp_encryption,'username' => $dbSettings->smtp_email,'password' => $dbSettings->smtp_password,'sendmail' => '/usr/sbin/sendmail -bs','from' => [
        'address' => $dbSettings->smtp_email,'name' => 'XXXXX'
    ],];

Config::set('mail',$mailConfigs);

// print_r(Config::get('mail'));
// Config here are reflected correctly if printed but when email is sent,it again uses the "from" address which is setup in .env and totally ignores the one setup above.

$res =  Mail::send([],$data,function ($message) use($mailConfigs)
{
    // email body,etc...
});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)