/** * Check to see if email address is a valid address and contains a MX record * * @param string $email The email to check * * @return mixed Either false if validation succeeded or a string which will be used as the error message (with the variable name appended) */ function src_validate_email($email, $config = null) { if ($config === null) { global $config; } $email = strtolower($email); if (!preg_match('/^' . get_preg_expression('email') . '$/i', $email)) { return 'EMAIL_INVALID'; } // Check MX record. // The idea for this is from reading the UseBB blog/announcement. :) if ($config['email_check_mx']) { list(, $domain) = explode('@', $email); if (src_checkdnsrr($domain, 'A') === false && src_checkdnsrr($domain, 'MX') === false) { return 'DOMAIN_NO_MX_RECORD'; } } return false; }
/** * Check if ip is blacklisted * This should be called only where absolutely necessary * * Only IPv4 (rbldns does not support AAAA records/IPv6 lookups) * * @author satmd (from the php manual) * @param string $mode register/post - spamcop for example is ommitted for posting * @param string|false $ip the IPv4 address to check * * @return false if ip is not blacklisted, else an array([checked server], [lookup]) */ function check_dnsbl($mode, $ip = false) { if ($ip === false) { $ip = $this->ip; } // Neither Spamhaus nor Spamcop supports IPv6 addresses. if (strpos($ip, ':') !== false) { return false; } $dnsbl_check = array('sbl.spamhaus.org' => 'http://www.spamhaus.org/query/bl?ip='); if ($mode == 'register') { $dnsbl_check['bl.spamcop.net'] = 'http://spamcop.net/bl.shtml?'; } if ($ip) { $quads = explode('.', $ip); $reverse_ip = $quads[3] . '.' . $quads[2] . '.' . $quads[1] . '.' . $quads[0]; // Need to be listed on all servers... $listed = true; $info = array(); foreach ($dnsbl_check as $dnsbl => $lookup) { if (src_checkdnsrr($reverse_ip . '.' . $dnsbl . '.', 'A') === true) { $info = array($dnsbl, $lookup . $ip); } else { $listed = false; } } if ($listed) { return $info; } } return false; }