作者 邓超

email

@@ -4,6 +4,7 @@ namespace Controller; @@ -4,6 +4,7 @@ namespace Controller;
4 4
5 use Lib\Mail\Mail; 5 use Lib\Mail\Mail;
6 use Lib\Mail\MailFun; 6 use Lib\Mail\MailFun;
  7 +use Lib\Verify;
7 use Model\emailSql; 8 use Model\emailSql;
8 9
9 10
@@ -28,7 +29,7 @@ class Login { @@ -28,7 +29,7 @@ class Login {
28 // $mail,$password,$imap,$smtp 29 // $mail,$password,$imap,$smtp
29 $formData = app()->request(['email','password','imap','smtp']); 30 $formData = app()->request(['email','password','imap','smtp']);
30 31
31 - if(empty($formData['email']) || !preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$formData['email'])){ 32 + if(empty($formData['email']) || !Verify::sEmail($formData['email'])){
32 app()->e('email_verify_error'); 33 app()->e('email_verify_error');
33 } 34 }
34 35
@@ -85,6 +85,22 @@ class MailFun { @@ -85,6 +85,22 @@ class MailFun {
85 return 0; 85 return 0;
86 } 86 }
87 87
  88 + /**
  89 + * 匹配邮箱
  90 + * @param $str
  91 + * @return mixed|string
  92 + * @author:dc
  93 + * @time 2023/11/24 10:04
  94 + */
  95 + public static function pregEmail($str){
  96 + preg_match('/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/',$str,$email);
  97 + if(empty($email[0])){
  98 + // 邮箱2
  99 + preg_match('/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/',$str,$email);
  100 + }
  101 + return $email[0]??'';
  102 + }
  103 +
88 104
89 /** 105 /**
90 * 邮件收件人/发件人 106 * 邮件收件人/发件人
@@ -97,17 +113,18 @@ class MailFun { @@ -97,17 +113,18 @@ class MailFun {
97 113
98 $strs = explode(',',$str); 114 $strs = explode(',',$str);
99 foreach ($strs as $k=>$s){ 115 foreach ($strs as $k=>$s){
100 - preg_match('/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/',$s,$email);  
101 - if(empty($email[0])){ 116 + $email = self::pregEmail($s);
  117 +
  118 + if(empty($email)){
102 $s = [ 119 $s = [
103 'email' => '', 120 'email' => '',
104 'name' => $s 121 'name' => $s
105 ]; 122 ];
106 }else{ 123 }else{
107 - $s = str_replace([$email[0],'"','<','>','&gt;','&lt;'],'',$s); 124 + $s = str_replace([$email,'"','<','>','&gt;','&lt;'],'',$s);
108 $s = trim($s); 125 $s = trim($s);
109 $s = [ 126 $s = [
110 - 'email' => $email[0], 127 + 'email' => $email,
111 'name' => $s 128 'name' => $s
112 ]; 129 ];
113 } 130 }
@@ -36,7 +36,15 @@ class Verify { @@ -36,7 +36,15 @@ class Verify {
36 * @time 2023/3/10 16:04 36 * @time 2023/3/10 16:04
37 */ 37 */
38 public static function sEmail(string $email){ 38 public static function sEmail(string $email){
39 - return preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email); 39 + if(preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email)){
  40 + return true;
  41 + }
  42 +
  43 + if(preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/',$email)){
  44 + return true;
  45 + }
  46 + return false;
  47 +
40 } 48 }
41 49
42 /** 50 /**