Update SMTP host validation for third-party services
Simplify validation to check DNS records instead of MX records Remove redundant port 80 checks that fail for mail-only subdomains Maintain compatibility with services like Mailgun and SendGrid
This commit is contained in:
parent
798bf268aa
commit
bb82e9a4b9
1 changed files with 7 additions and 14 deletions
21
custom/vendor/PHPMailer.Lite.php
vendored
21
custom/vendor/PHPMailer.Lite.php
vendored
|
|
@ -709,18 +709,15 @@ class PHPMailerLite
|
||||||
}
|
}
|
||||||
$tld = substr($url, strpos($url, ".") + 1);
|
$tld = substr($url, strpos($url, ".") + 1);
|
||||||
if ($validate === "is_valid") {
|
if ($validate === "is_valid") {
|
||||||
$url = $tld;
|
// Just check if the SMTP host is reachable via DNS (A record)
|
||||||
|
// The original check compared SMTP host to MX records which breaks
|
||||||
|
// third-party SMTP services like Mailgun, SendGrid, etc.
|
||||||
|
return checkdnsrr($url, 'A') || checkdnsrr($url, 'AAAA');
|
||||||
}
|
}
|
||||||
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $tld, $match)) {
|
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $tld, $match)) {
|
||||||
getmxrr($match['domain'], $mx_details);
|
getmxrr($match['domain'], $mx_details);
|
||||||
if (is_array($mx_details) && count($mx_details) > 0) {
|
if (is_array($mx_details) && count($mx_details) > 0) {
|
||||||
if ($validate === "is_valid") {
|
return reset($mx_details);
|
||||||
if ($url == reset($mx_details)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return reset($mx_details);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -961,12 +958,8 @@ class PHPMailerLite
|
||||||
$rz = false;
|
$rz = false;
|
||||||
}
|
}
|
||||||
if ($rz) {
|
if ($rz) {
|
||||||
$rz = false;
|
// Check DNS records instead of port 80 (mail-only subdomains don't have web servers)
|
||||||
$check = @fsockopen($domn, 80, $errno, $errstr, 1);
|
$rz = (checkdnsrr($domn, 'MX') || checkdnsrr($domn, 'A'));
|
||||||
if ($check) {
|
|
||||||
$rz = true;
|
|
||||||
@fclose($check);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($rz) {
|
if ($rz) {
|
||||||
$rz = (bool) preg_match('/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD', $email);
|
$rz = (bool) preg_match('/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD', $email);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue