Swiftmailer useFileTransport property on the fly

Hello, I am coding with Yii2, the task to accomplish is to send emails either store locally or send them using SMTP it will depends of user input, what I need is to change on runtime the value of useFileTransport property, checking the documentation of Swiftmailer, just the method setTransport is in charge of properties such as host, port, encryption etc but no useFileTransport.

The configuration of mailer is managed by web.php, since this file is loaded once I cannot update that property. So any idea will be welcome, if I change manually useFileTransport from true to false everything works, the idea is the user interact with a view to set it on runtime.

Thanks in advanced.

Why not just call Yii::$app->mailer->useFileTransport = true/false whenever you need it?

1 Like

Yes, thank you Bizley, in fact, that was the solution, here it is the solution:
if($transport == ‘local’){
\Yii::$app->mailer->useFileTransport=true;
}
else{
\Yii::$app->mailer->useFileTransport=false;
}

All the best