T
T
Tim2020-09-18 09:59:11
Yii
Tim, 2020-09-18 09:59:11

How to remove Swiftmailer settings from config?

Good day. I need to implement my own class to send mail. Is it possible to take out these settings and change them dynamically?

'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => '',
                'port' => '',
                'username' => ' ',
                'password' =>  '',
                'encryption' => 'ssl',
            ],

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2020-09-18
@Tim-A-2020

You take out the config in a separate file where you need:

<?php
return [
    'support' => [
        'class' => 'yii\swiftmailer\Mailer',
        'useFileTransport' => false,
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'mailmail.ru',
            'username' => '[email protected]',
            'password' => 'c',
            'port' => '465',
            'encryption' => 'ssl',
        ],
    ],
    'noReply' => [
        'class' => 'yii\swiftmailer\Mailer',
        'useFileTransport' => false,
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'mail.mail.ru',
            'username' => '[email protected]',
            'password' => '',
            'port' => '465',
            'encryption' => 'ssl',
        ],
    ],
];

And in web.php
$mailers = require __DIR__ . '/../components/mailer/config.php';
'components'=> [
    ...
    'supportMailer' => $mailers['support'],
    'noreplyMailer' => $mailers['noReply'],
    ...
]

Calling:
Yii::$app=>supportMailer ...
Yii::$app=>noreplyMailer...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question