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