1.配置文件
路径 application/api/config.php,在里面添加下面代码
'mail_type' => '1',
//smtp可以是qq邮箱或者网易云邮箱
'mail_smtp_host' => 'smtp.163.com',
'mail_smtp_port' => '465',
'mail_smtp_user' => '用户名',
//邮箱授权码
'mail_smtp_pass' => '',
'mail_verify_type' => '2',
'mail_from' => '你的邮箱',
2.控制器
use app\common\library\Email;
public function test()
{
$email = new Email();
$res=$email->
//标题
subject('这里是邮件标题')->
//发给谁
to('123456@qq.com')->
//内容
message('这里是邮件正文')->
send();
if($res!==false){
$this->success('返回成功');
}else{
$this->error('返回失败',$email->getError());
}
}