Viewed   121 times

How can I check for duplicate email addresses in PHP, with the possibility of Gmail's automated labeler and punctuation in mind?

For example, I want these addressed to be detected as duplicates:

         [email protected]
        [email protected]
   [email protected]
  [email protected]

Despite what Daniel A. White claims: In Gmail, dots at random places before the '@' (and label) can be placed as much as you like. user.[email protected] and [email protected] are in fact the same user.

 Answers

2
$email_parts    = explode('@', $email);

// check if there is a "+" and return the string before
$before_plus    = strstr($email_parts[0], '+', TRUE);
$before_at      = $before_plus ? $before_plus : $email_parts[0];

// remove "."
$before_at      = str_replace('.', '', $before_at);

$email_clean    = $before_at.'@'.$email_parts[1];
Friday, November 11, 2022
 
hunterr
 
3

First, these are not variables, but constants.

And you can check their existence by using the defined() function :

bool defined ( string $name )

Checks whether the given constant exists and is defined.

Thursday, December 1, 2022
 
5

Using regular expression to validate emails is tricky

Try the following email as an input to your regex ie:^[w.-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,6}$

[email protected]

You can read more about email regex validation at http://www.regular-expressions.info/email.html

If you are doing this for an app then use email validation by sending an email to the address provided rather than using very complex regex.

Thursday, October 20, 2022
4

There is: is_uploaded_file(). When dealing with uploaded files, you should always use it (and its cousin move_uploaded_file()) for security reasons.

Tuesday, September 6, 2022
 
1

are there any edge cases where a valid email address could fail an MX lookup check?

Yes, in that where there is no MX record, MTAs fall back to using the A record instead. So only allowing MX records would fail a class of mail servers that work in the real world.

Allowing any name with an MX or A record at least detects obvious mistypings that result in NXDOMAIN. However it will still allow mistypings that end up at squatter sites. A further step for addresses resolved by A records might be to check where port 25 is accepting connections on that address.

Saturday, August 20, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :