本文介绍了如何设置动态SMTP详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与一个项目合作,我需要在每个管理员登录名上更新SMTP详细信息.我正在将详细信息存储在数据库中,什么是最好的方法?

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.

推荐答案

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

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.

<?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/

这篇关于如何设置动态SMTP详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 17:56