作者 邓超

x

... ... @@ -3,6 +3,7 @@
namespace Controller;
use Lib\Mail\Mail;
use Lib\Mail\MailFun;
use Model\emailSql;
... ... @@ -51,6 +52,11 @@ class Login {
app()->e('email_server_error');
}
// 验证smtp登录
if(!MailFun::smtpLoginTest($formData['smtp'],$formData['email'],$formData['password'])){
app()->e('email_smtp_server_error');
}
// 是否存在
$id = db()->value(emailSql::hasEmail($formData['email']));
... ...
... ... @@ -16,7 +16,8 @@ return [
'server_error' => '服务器异常',
'email_server_error' => '连接邮件服务器失败,请检查邮件服务器地址是否正确',
'email_server_error' => 'IMAP:连接邮件服务器失败,请检查邮件服务器地址是否正确',
'email_smtp_server_error' => 'SMTP:连接邮件服务器失败,请检查邮件服务器地址是否正确',
'login_error' => '登录失败',
'login_error_imap' => '登录失败,请检查密码是否正确或者是否开启imap/smtp服务',
... ...
... ... @@ -238,4 +238,39 @@ class MailFun {
return $oldStr == base64_encode(base64_decode($str));
}
/**
* 测试登录
* @param $smtp
* @param $email
* @param $password
* @return bool
* @author:dc
* @time 2023/11/7 10:47
*/
public static function smtpLoginTest($smtp,$email,$password){
// 邮件对象
$mail = new PHPMailer();
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_OFF;//调试输出 SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = $smtp; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = $email; //SMTP username
$mail->Password = $password; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
$mail->CharSet = 'utf-8';
$mail->Encoding = PHPMailer::ENCODING_QUOTED_PRINTABLE;
try {
return $mail->smtpConnect();
}catch (\Throwable $e){}
return false;
}
}
... ...