Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29929

Find stripped e-mail in SQL

$
0
0

I want to prevent users from using the same e-mail multiple times. Many servers, however, are configured in a way that e-mails to john.doe@example.com would go in the same inbox as j.oh.ndoe..@exmaple.com or johndoe+abc123@example.com. Therefore, I applied a simple PHP function to strip an e-mail from its dots and ignore anything that's after a + sign. Here is the PHP function I am using:

function strip_email ($email) {
    $id = explode("@", $email)[0]; //what is before the '@'
    $noplus = explode("+", $id)[0]; //what is before the '+'
    $nodots = str_replace(".", "", $noplus); //and with dots removed
    return $nodots. "@" .$provider;
}

However, I would like to register users with the exact e-mail they have provided (not stripped). E.g., if the user has entered john.doe+demo@example.com I use this e-mail for the MySQL record as this is where the user wants to be reached (for instance some servers use the string after + to label e-mails or put them in different folders).

Upon new registrations, I am checking whether the e-mail exists in the following way:

$email = $_POST['email'];
$query = "SELECT e-mail FROM users WHERE email='$email' LIMIT 1";
$result = mysqli_query($db, $user_check_query);
$row = mysqli_fetch_assoc($result);
if ($row) ... #email already in use

The issue is if the user has entered john..doe+mylabel@example.com that won't match any entry in the database, neither would it if the search value is stripped (johndoe@example.com).

Should I create a second row in my table and store as well the stripped e-mail?


Viewing all articles
Browse latest Browse all 29929


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>