Check If Email Exist PHP

Check if a string is an email address in PHP

This is not a great method and doesn't check if the email exists but it checks if it looks like an email with the @ and domain extension.

function checkEmail($email) {
$find1 = strpos($email, '@');
$find2 = strpos($email, '.');
return ($find1 !== false && $find2 !== false && $find2 > $find1);
}

$email = 'name@email.com';
if ( checkEmail($email) ) {
echo $email . ' looks like a valid email address.';
}

Using PHP Check Email ID Already Exist Or Not in Database

A good way is to create a UNIQUE index on the email column, then you could use INSERT IGNORE INTO instead of simple insert, and then you could check affected_rows to determine if the insertion was successful or the email already exists in the table:

$stmt = mysqli_prepare($conn, "INSERT IGNORE INTO people (email) VALUES (?);");

mysqli_stmt_bind_param($stmt, 's', $email);
$result = mysqli_stmt_execute($stmt);

if(mysqli_affected_rows($result) === 1) {
// email was new, here you should send the email
$mail = new PHPMailer;
}
else {
echo "This email has already been registered";
}

How to check if an email address exists without sending an email?

There are two methods you can sometimes use to determine if a recipient actually exists:

  1. You can connect to the server, and issue a VRFY command. Very few servers support this command, but it is intended for exactly this. If the server responds with a 2.0.0 DSN, the user exists.

    VRFY user
  2. You can issue a RCPT, and see if the mail is rejected.

    MAIL FROM:<>
    RCPT TO:<user@domain>

If the user doesn't exist, you'll get a 5.1.1 DSN. However, just because the email is not rejected, does not mean the user exists. Some server will silently discard requests like this to prevent enumeration of their users. Other servers cannot verify the user and have to accept the message regardless.

There is also an antispam technique called greylisting, which will cause the server to reject the address initially, expecting a real SMTP server would attempt a re-delivery some time later. This will mess up attempts to validate the address.

Honestly, if you're attempting to validate an address the best approach is to use a simple regex to block obviously invalid addresses, and then send an actual email with a link back to your system that will validate the email was received. This also ensures that they user entered their actual email, not a slight typo that happens to belong to somebody else.

PHP file to check if email exists in database

You should replace usuario=? in $sql = "SELECT usuario FROM users WHERE usuario=?"; for emailuser=? and replace the bind value to $email. You are currently not checking for email, instead you are checking for name.

check that if email exists in data base or not

You can query this to know if a user is already registered.

SELECT gmail
FROM users
WHERE gmail = '$gmail'

If you have 1 row returned, so this user is already registered.

Once you find if this user exists, you can do your query with the INSERT clause.



Related Topics



Leave a reply



Submit