正在显示
3 个修改的文件
包含
43 行增加
和
1 行删除
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | namespace Controller; | 3 | namespace Controller; |
4 | 4 | ||
5 | use Lib\Mail\Mail; | 5 | use Lib\Mail\Mail; |
6 | +use Lib\Mail\MailFun; | ||
6 | use Model\emailSql; | 7 | use Model\emailSql; |
7 | 8 | ||
8 | 9 | ||
@@ -51,6 +52,11 @@ class Login { | @@ -51,6 +52,11 @@ class Login { | ||
51 | app()->e('email_server_error'); | 52 | app()->e('email_server_error'); |
52 | } | 53 | } |
53 | 54 | ||
55 | + // 验证smtp登录 | ||
56 | + if(!MailFun::smtpLoginTest($formData['smtp'],$formData['email'],$formData['password'])){ | ||
57 | + app()->e('email_smtp_server_error'); | ||
58 | + } | ||
59 | + | ||
54 | 60 | ||
55 | // 是否存在 | 61 | // 是否存在 |
56 | $id = db()->value(emailSql::hasEmail($formData['email'])); | 62 | $id = db()->value(emailSql::hasEmail($formData['email'])); |
@@ -16,7 +16,8 @@ return [ | @@ -16,7 +16,8 @@ return [ | ||
16 | 16 | ||
17 | 'server_error' => '服务器异常', | 17 | 'server_error' => '服务器异常', |
18 | 18 | ||
19 | - 'email_server_error' => '连接邮件服务器失败,请检查邮件服务器地址是否正确', | 19 | + 'email_server_error' => 'IMAP:连接邮件服务器失败,请检查邮件服务器地址是否正确', |
20 | + 'email_smtp_server_error' => 'SMTP:连接邮件服务器失败,请检查邮件服务器地址是否正确', | ||
20 | 21 | ||
21 | 'login_error' => '登录失败', | 22 | 'login_error' => '登录失败', |
22 | 'login_error_imap' => '登录失败,请检查密码是否正确或者是否开启imap/smtp服务', | 23 | 'login_error_imap' => '登录失败,请检查密码是否正确或者是否开启imap/smtp服务', |
@@ -238,4 +238,39 @@ class MailFun { | @@ -238,4 +238,39 @@ class MailFun { | ||
238 | return $oldStr == base64_encode(base64_decode($str)); | 238 | return $oldStr == base64_encode(base64_decode($str)); |
239 | } | 239 | } |
240 | 240 | ||
241 | + | ||
242 | + /** | ||
243 | + * 测试登录 | ||
244 | + * @param $smtp | ||
245 | + * @param $email | ||
246 | + * @param $password | ||
247 | + * @return bool | ||
248 | + * @author:dc | ||
249 | + * @time 2023/11/7 10:47 | ||
250 | + */ | ||
251 | + public static function smtpLoginTest($smtp,$email,$password){ | ||
252 | + | ||
253 | + // 邮件对象 | ||
254 | + $mail = new PHPMailer(); | ||
255 | + //Server settings | ||
256 | + $mail->SMTPDebug = SMTP::DEBUG_OFF;//调试输出 SMTP::DEBUG_SERVER; //Enable verbose debug output | ||
257 | + $mail->isSMTP(); //Send using SMTP | ||
258 | + $mail->Host = $smtp; //Set the SMTP server to send through | ||
259 | + $mail->SMTPAuth = true; //Enable SMTP authentication | ||
260 | + $mail->Username = $email; //SMTP username | ||
261 | + $mail->Password = $password; //SMTP password | ||
262 | + $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption | ||
263 | + $mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` | ||
264 | + $mail->CharSet = 'utf-8'; | ||
265 | + $mail->Encoding = PHPMailer::ENCODING_QUOTED_PRINTABLE; | ||
266 | + | ||
267 | + try { | ||
268 | + return $mail->smtpConnect(); | ||
269 | + }catch (\Throwable $e){} | ||
270 | + | ||
271 | + return false; | ||
272 | + | ||
273 | + } | ||
274 | + | ||
275 | + | ||
241 | } | 276 | } |
-
请 注册 或 登录 后发表评论