Home > Backend Development > PHP Tutorial > Can you verify email validity only using PHP?

Can you verify email validity only using PHP?

Mary-Kate Olsen
Release: 2024-12-17 06:58:25
Original
286 people have browsed it

Can you verify email validity only using PHP?

Verifying Email Validity with PHP

You may wonder whether it is possible to verify the validity of an email address using PHP alone. Are not. Unfortunately, with just a single PHP method, you cannot verify (with enough accuracy to trust) that an email actually exists. However, you can still check if an email is formatted correctly using the filter_var method:

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Email hợp lệ
}
Copy after login

Alternatively, you can add another check by extracting export the domain and run the checkdnsrr function:

if (checkdnsrr($domain)) {
    // Miền ít nhất có bản ghi MX, cần thiết để nhận email
}
Copy after login

However, it is important to note that:

  • Spamers also know about the "connection trick" (where you start sending an email and rely on the server returning it at that time). Many email servers accept all incoming email, making validation difficult.
  • If the accuracy of email address verification is extremely important, the accepted way is to ask users to reply to your email. Send them a complete email with a link they must click to get verified. This is not spamming and you can ensure that any response has a valid address.

The above is the detailed content of Can you verify email validity only using PHP?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template