Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Validation/DNSCheckValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ class DNSCheckValidation implements EmailValidation
*/
private $dnsGetRecord;

public function __construct(?DNSGetRecordWrapper $dnsGetRecord = null)
/**
* @var bool
*/
private $requireMX;

public function __construct(?DNSGetRecordWrapper $dnsGetRecord = null, bool $requireMX = false)
{
if (!function_exists('idn_to_ascii')) {
throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
Expand All @@ -74,6 +79,7 @@ public function __construct(?DNSGetRecordWrapper $dnsGetRecord = null)
}

$this->dnsGetRecord = $dnsGetRecord;
$this->requireMX = $requireMX;
}

public function isValid(string $email, EmailLexer $emailLexer): bool
Expand Down Expand Up @@ -174,6 +180,11 @@ private function validateDnsRecords($host): bool
return false;
}
}

if (empty($this->mxRecords) && $this->requireMX) {
$this->error = new InvalidEmail(new ReasonNoDNSRecord(), '');
}

return true;
}

Expand Down