【问题标题】:How to set dynamic SMTP details laravel如何设置动态 SMTP 详细信息 laravel
【发布时间】:2017-07-26 08:58:37
【问题描述】:

我正在处理一个项目,我需要在每次管理员登录时更新 SMTP 详细信息。我将详细信息存储在数据库中,最好的方法是什么。

【问题讨论】:

    标签: laravel smtp


    【解决方案1】:

    我自己的方法:从引导加载的config/app.php 提供程序列表中删除Illuminate\Mail\MailServiceProvider::class,并创建一个新的中间件以在识别用户后手动加载它。

    <?php
    
    namespace App\Http\Middleware;
    
    use Illuminate\Contracts\Auth\Guard;  
    use Illuminate\Mail\TransportManager;
    
    use Closure;  
    use Mail;  
    use Config;  
    use App;
    
    class OverwriteMail  
    {
        public function __construct(Guard $auth)
        {
            $this->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);
        }
    }
    

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

    【讨论】:

      【解决方案2】:

      我认为这应该回答您的问题: https://laravel.io/index.php/forum/07-22-2014-swiftmailer-with-dynamic-mail-configuration

      只需将其存储在数据库表中,然后使用Config 外观即可即时设置详细信息。

      【讨论】:

      • 当然,您必须根据自己的需要进行调整,请发布您的问题的更多详细信息。
      猜你喜欢
      • 1970-01-01
      • 2011-12-08
      • 2011-08-30
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-27
      • 1970-01-01
      相关资源
      最近更新 更多