yii2 change transport

To change the transport in Yii or Yii2, you would need to modify the configuration file for the mail component. The transport is responsible for sending out emails, and Yii2 supports multiple transports such as SMTP, PHP's mail function, and more.

In your Yii2 application, locate the configuration file, typically named main.php or web.php, depending on your application's structure. This file is usually found in the config directory.

Within the configuration file, locate the components section, and find the mail component configuration. It should look something like this:

'components' => [
    'mail' => [
        'class' => 'yii\swiftmailer\Mailer',
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.example.com',
            'username' => 'your_username',
            'password' => 'your_password',
            'port' => '587',
            'encryption' => 'tls',
    // Other components...

To change the transport, you can modify the 'transport' configuration within the mail component. For example, if you want to use the PHP mail function, you can change it to the following:

'transport' => [
    'class' => 'Swift_MailTransport',

If you want to use a different SMTP server, you would need to update the relevant configuration options such as 'host', 'username', 'password', 'port', and 'encryption'. Make sure to replace the placeholders with the actual values specific to your SMTP server.

Once you have made the necessary changes, save the configuration file. Your Yii2 application should now use the new transport configuration for sending emails.

Remember to import the necessary classes at the top of your configuration file if they are not already imported:

use yii\swiftmailer\Mailer;
use Swift_SmtpTransport;
use Swift_MailTransport;

That's it! You have successfully changed the transport in Yii or Yii2.