1、修改配置,位于common/config/main-local.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' =>false,//这句一定有,false发送邮件,true只是生成邮件在runtime文件夹下,不发邮件
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.163.com', //每种邮箱的host配置不一样
'username' => '******@163',
'password' => '******',
'port' => '25',
'encryption' => 'tls',
],
'messageConfig'=>[
'charset'=>'UTF-8',
'from'=>['******@163.com'=>'admin']
],
],

2、新建一个控制器,内容如下
$emil=000000@qq.com
$mail= Yii::$app->mailer->compose();
$mail->setTo($email);
$mail->setSubject("邮件的标题");
//$mail->setTextBody('zheshisha '); //发布纯文字文本
$mail->setHtmlBody("<br>邮件内容"); //发布可以带html标签的文本
if($mail->send()) {
echo "success";
}else{
echo "failse";
die();
}