How to make basic judgments on common mailboxes in PHP

Source: Internet
Author: User
Before sending the email, the user's basic information already exists in the Database. If it is an incorrect email address or malicious multi-account registration, you need to filter it out, the following describes how to determine frequently used mailboxes in PHP.

Before sending the email, the user's basic information already exists in the Database. If it is an incorrect email address or malicious multi-account registration, you need to filter it out, the following describes how to determine frequently used mailboxes in PHP.

More and more websites want users to use their email addresses to register or bind their email addresses. At this time, they need to confirm the correctness of their email addresses. Some users use emails for activation to make judgments, to activate an account, but there is a problem: Before the email is sent, the basic information of the user already exists in the database, if it is a wrong email address or a malicious multi-account registration, too many non-active accounts will occupy the database storage space. In this case, you need to filter these mailboxes before, therefore, the author writes the following method to filter mailboxes.

The Code is as follows:


/**
* @ Todo user input Security Detection
* @ Param $ inputString user input information
* @ Return true/false
* @ Final: You can change the content to be filtered based on your needs.
*/
Public function checkUserInput ($ inputString ){
If (strpos ('script', $ inputString )! = False) {// check whether script is included
Return FALSE;
} Else if (strpos ('iframe', $ inputString )! = False) {// check whether the iframe framework is included
Return FALSE;
} Else {
Return TRUE;
}
}

/**
* @ Todo checkeemail
* @ Param emailString
* @ Return false/true
*/
Public function checkEmail ($ emailString ){
If ($ this-> checkUserInput ($ emailString) === TRUE) {// checks whether sensitive words exist.
If (strpos ('@', $ emailString )! = FALSE) {// check whether @ characters exist
$ EmailArr = explode ('@', $ emailString );
If (count ($ emailArr)> 2) {// check whether multiple @ characters exist
Return FALSE;
} Else {
If (in_array ('@'. $ emailArr [1], Yii: app ()-> params ['mail _ suffix ']) {// check whether the suffix meets common mailbox suffixes
Return TRUE;
} Else {
Return FALSE;
}
}
} Else {
Return FALSE;
}
} Else {
Return FALSE;
}
}


Here, I define an array with the suffix of a common mailbox, as shown in the following code:

// Common mailbox suffixes, which can be added based on specific requirements

The Code is as follows:


'Mail _ suffix '=> array (' @ hotmail.com ',
'@ Msn.com ',
'@ Yahoo.com ',
'@ Gmail.com ',
'@ Aim.com ',
'@ Aol.com ',
'@ Mail.com ',
'@ Walla.com ',
'@ Inbox.com ',
'@ 126.com ',
'@ 163.com ',
'@ Sina.com ',
'@ 21cn.com ',
'@ Sohu.com ',
'@ Yahoo.com.cn ',
'@ Tom.com ',
'@ Qq.com ',
'@ Etang.com ',
'@ Eyou.com ',
'@ 56.com ',
'@ X.cn ',
'@ Chinaren.com ',
'@ Sogou.com ',
'@ Citiz.com ',
),


The mailbox filtering method has been completed. You can further improve it on this basis!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.