小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

php – 如何在laravel 5中有條件地更改郵件傳輸器?

 印度阿三17 2019-07-11

我用laravel 5.3.
我需要發(fā)送具有不同憑據(jù)(主機,端口,用戶名,密碼)的郵件.

我可以發(fā)送默認(rèn)的laravel配置(.env).

但我需要動態(tài)級別的實現(xiàn).

我制作配置數(shù)組,

   // Pre-Mail Setup Config.
            $store_config = [
              'list' =>  
                  //SET 1
                 ['from_name' => 'sender1',
                'from_address' => 'from_adderss1',
                'return_address' => 'reply1',
                'subject' => 'subject1',
                'host' => 'host1',
                'port' => 'post1',
                'authentication' => 'auth1',
                'username' => 'uname1',
                'password' => 'pass1'],
                 //SET 2
                [.........],
                 //SET 3
                [.........]
            ];

我嘗試以下發(fā)送郵件,但它不起作用.

 // Inside Foreach.
$transporter = \Swift_MailTransport::newInstance('smtp.gmail.com', 465, 'ssl')
                ->setUsername($config['username'])
                ->setPassword($config['password']);

$mailer = \Swift_Mailer::newInstance($transporter);


$message->from($config['from_address'], $config['from_name']);


$message->to('To_Email, 'Name')
        ->subject('My Subject')
        ->setBody('My Content', 'text/html');
$mailer->send($message);

我的代碼出了什么問題?

可能嗎?

或任何其他解決方案?

解決方法:

最后我找到了解決這個問題的方法.

實際上Laravel 5并不完全支持這種多傳輸器配置.

所以我使用替代包來實現(xiàn)它.

我的代碼是,

    foreach ($store_configs['list'] as $store_config) {

        // Create Custom Mailer Instances.
        $mailer = new \YOzaz\LaravelSwiftmailer\Mailer();
        $transport = \Swift_SmtpTransport::newInstance(
                                           $store_config['host'], 
                                           $store_config['port'], 
                                           $store_config['authentication']);

        // Assign Dynamic Username.
        $transport->setUsername($store_config['username']);

        // Assign Dynamic Password.
        $transport->setPassword($store_config['password']);
        $smtp = new \Swift_Mailer($transport);
        $mailer->setSwiftMailer($smtp);



            $mailer->send('template', ['data'], function ($message) use ($queue) {
                // Default Response goes here
                $message->from('From Address', 'From Name');

                $message->to($email, 'Name')->subject('My Subject')
                    ->setBody('My HTML', 'text/html');
                $message->getSwiftMessage();
                //
            });
   }

它適用于多個動態(tài)運輸車.

謝謝大家 !

來源:https://www./content-1-316501.html

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多