Is it possible to check to see if the email suppied by the user has a valid domain? I had a couple of people who registered on my site and they provided an invalid email address. Is there a way to do this without using function?
I am using this code but it always say bad domain name
if(!checkdnsrr(array_pop(explode(“@”, $email)), “MS”)) {
echo “”;
} else {
I guess I can always delete the user if they don’t activate your account to verify the email
the strange thing is that in my phpmailer, if the mail is not send, I have included some files to delete the user but how come it still can send an email to that invalid address?
$mail->addAttachment(‘images/phpmailer_mini.png’);
if ($mail->send()) {
echo "<meta http-equiv='refresh' content='0;url=../student_registration.php?id=".htmlspecialchars($userid)."&email=".htmlspecialchars($email)."&username=".htmlspecialchars($uid)."'>";
// header(“Location: …/student_registration.php?id=”.htmlspecialchars($userid).“&email=”.htmlspecialchars($email).“&username=”.htmlspecialchars($uid).“”);
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
$sql13 = “DELETE FROM users WHERE user_uid = ? AND user_email = ?;”;
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql13)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $username, $email);
mysqli_stmt_execute($stmt);
$sql14 = "DELETE FROM memberships WHERE user_uid = ? AND user_email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql14)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $username, $email);
mysqli_stmt_execute($stmt);
maybe this helps?
This is the library used in the client area to validate email addresses.
By default, it uses complex expression to make sure the email addresses match the official statuses, but they have other checks as well.
So I guess there is no other easy way to do this?
Email addresses are complex, and there are many long documents which describe how an email address should work and what it should look like. I read some of them. Having to implement all of those rules is… daunting.
If you want something simple, you can use filter_var($email, FILTER_VALIDATE_EMAIL)
, which is a built-in function of PHP which does basic email format validation. It’s not entirely compliant with the format rules, but it’s good enough.
However, while an email address is syntactically valid, that doesn’t mean it can actually receive email. You’d need to do check to look whether a valid mail server is configured on the domain and connect to that mail server to validate the address is present first. And even that’s not fool proof.
So no, there is no easy way to validate email addresses.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.