Вопрос

I'd like to use different smtp account for sending emails depending on context of the application. So I found this answer, but it work only only for changing username and password.

Changing smtp settings in SwiftMailer dynamically

I need to dynamically change host as well.

Any idea will be appreciated.

Это было полезно?

Решение

The same way as you set username and password, you can set host, port and encryption:

$transport = $fromYourMailerVariable->getTransport();
$transport
    ->setUserName(...)
    ->setPassword(...)
    ->setHost(...)
    ->setPort(...)
    ->setEncryption(...);

Or just create different mailers (with different transports):

$transport1 = Swift_SmtpTransport::newInstance('localhost');

$transport2 = Swift_SmtpTransport::newInstance('smtp.domain.com', 666)
                ->setUsername('user')
                ->setPassword('pass');

$transport3 = Swift_SendmailTransport::newInstance('/usr/sbin/exim -bs');

$transport4 = Swift_MailTransport::newInstance();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top