yii2邮箱发送
yii2 邮件发送 163邮箱
1.在配置文件main-local.php components=>[]里面配置
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.163.com', //每种邮箱的host配置不一样
'username' => '18310496083@163.com',
'password' => '774330595a',
'port' => '25',
'encryption' => 'tls',
],
'messageConfig'=>[
'charset'=>'UTF-8',
'from'=>['18310496083@163.com'=>'shanzezhao']
],
],
2.controller控制器中 代码: