作者 邓超

email

... ... @@ -4,6 +4,7 @@ namespace Controller;
use Lib\Mail\Mail;
use Lib\Mail\MailFun;
use Lib\Verify;
use Model\emailSql;
... ... @@ -28,7 +29,7 @@ class Login {
// $mail,$password,$imap,$smtp
$formData = app()->request(['email','password','imap','smtp']);
if(empty($formData['email']) || !preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$formData['email'])){
if(empty($formData['email']) || !Verify::sEmail($formData['email'])){
app()->e('email_verify_error');
}
... ...
... ... @@ -85,6 +85,22 @@ class MailFun {
return 0;
}
/**
* 匹配邮箱
* @param $str
* @return mixed|string
* @author:dc
* @time 2023/11/24 10:04
*/
public static function pregEmail($str){
preg_match('/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/',$str,$email);
if(empty($email[0])){
// 邮箱2
preg_match('/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/',$str,$email);
}
return $email[0]??'';
}
/**
* 邮件收件人/发件人
... ... @@ -97,17 +113,18 @@ class MailFun {
$strs = explode(',',$str);
foreach ($strs as $k=>$s){
preg_match('/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/',$s,$email);
if(empty($email[0])){
$email = self::pregEmail($s);
if(empty($email)){
$s = [
'email' => '',
'name' => $s
];
}else{
$s = str_replace([$email[0],'"','<','>','&gt;','&lt;'],'',$s);
$s = str_replace([$email,'"','<','>','&gt;','&lt;'],'',$s);
$s = trim($s);
$s = [
'email' => $email[0],
'email' => $email,
'name' => $s
];
}
... ...
... ... @@ -36,7 +36,15 @@ class Verify {
* @time 2023/3/10 16:04
*/
public static function sEmail(string $email){
return preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email);
if(preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email)){
return true;
}
if(preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/',$email)){
return true;
}
return false;
}
/**
... ...