IsSMTP(); $mail->isHTML(true); $mail->AltBody = "更好地查看这封邮件,请打开HTML兼容视图"; // optional, comment out and test $mail->CharSet = 'utf-8'; // 编码格式为utf8,不设置编码的话,中文会出现乱码 $mail->SMTPDebug = 0; // enables SMTP debug information $mail->SMTPAuth = true; // enable SMTP authentication $mail->Host = "smtp.163.com"; // 发送方的SMTP服务器地址 $mail->Port = 25; // 端口 $mail->Password = "jonlin2468"; //客户端授权密码,而不是邮箱的登录密码! $mail->Username = "jonlinhuang@163.com"; // 发件人邮箱 $mail->SetFrom('jonlinhuang@163.com', '安全猫-系统邮件'); // 安全猫科技有限公司co.ltd $code=rand(100000,999999); session('code', $code, 1800); $mail->Subject = '邮箱验证'; $mail->AddAddress($email); $mail->MsgHTML('邮箱验证码 您的验证码是:'.$code.',30分钟内有效,如果非本人操作无需理会!'); $res = $mail->send(); if($res == true){ return "发送成功"; }else{ echo "Message could not be sent."; echo "Mailer Error: " . $mail->ErrorInfo;// 输出错误信息 } } }