What are the potential pitfalls of using checkdnsrr for email validation in PHP?
Using checkdnsrr for email validation in PHP can be unreliable as it only checks if the domain has a DNS record, not if the email address is valid or if the domain can receive emails. It's better to use a more comprehensive email validation library or service to ensure accurate validation.
// Example using a more comprehensive email validation library like egulias/email-validator
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\RFCValidation;
$validator = new EmailValidator();
$isValid = $validator->isValid('test@example.com', new RFCValidation());
if ($isValid) {
echo 'Email is valid';
} else {
echo 'Email is not valid';
}