I use xampp server with yii2 and swiftmailer extension.I configured my swiftmailer to use my gmail as smtp to send mails.Following is my code.
In the components's section of your common/main-local.php
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@backend/mail',
'useFileTransport' => false,//to send mails to real email addresses else will get stored in your mail/runtime folder
//comment the following array to send mail using php's mail function
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'username@gmail.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
],
In your Controller
\Yii::$app->mail->compose('your_view', ['params' => $params])
->setFrom([\Yii::$app->params['supportEmail'] => 'Test Mail'])
->setTo('to_email@xx.com')
->setSubject('This is a test mail ' )
->send();
This should work! Hope this will help you!