function validEmail($email, $extended = false) { if (empty($email) or !is_string($email)) { return false; } if (!preg_match('/^([a-z0-9_\'&\\.\\-\\+])+\\@(([a-z0-9\\-])+\\.)+([a-z0-9]{2,10})+$/i', $email)) { return false; } if (!$extended) { return true; } $config = acymailing_config(); if ($config->get('email_checkpopmailclient', false)) { if (preg_match('#^.{1,5}@(gmail|yahoo|aol|hotmail|msn|ymail)#i', $email)) { return false; } } if ($config->get('email_checkdomain', false) and function_exists('getmxrr')) { $domain = substr($email, strrpos($email, '@') + 1); $mxhosts = array(); $checkDomain = getmxrr($domain, $mxhosts); if (!empty($mxhosts) && strpos($mxhosts[0], 'hostnamedoesnotexist')) { array_shift($mxhosts); } if (!$checkDomain || empty($mxhosts)) { $dns = @dns_get_record($domain, DNS_A); if (empty($dns)) { return false; } } } return true; }
/** * Get mail web application url * * @example `bob@idarex.com` Web url is `http://exmail.qq.com` * @param $email * @return string */ public static function getWebAppUrl($email) { list(, $emailDomain) = explode('@', $email); switch ($emailDomain) { case "163.com": return "http://mail.163.com"; break; case "qq.com": return "http://mail.qq.com"; break; case "126.com": return "http://mail.126.com"; break; case "gmail.com": return "http://mail.google.com"; break; default: $mxHosts = []; if (getmxrr($emailDomain, $mxHosts)) { foreach ($mxHosts as $row) { if (isset(static::$mxServerWebAppUrl[$row])) { return static::$mxServerWebAppUrl[$row]; } } } return "http://mail.{$emailDomain}"; break; } }
function ValidateEmailHost($email, $hosts = 0) { if (!$this->ValidateEmailAddress($email)) { return 0; } //if(strpos(PHP_OS,'WIN') !== false) return(-1); $user = strtok($email, "@"); $domain = strtok(""); if (getmxrr($domain, &$hosts, &$weights)) { $mxhosts = array(); for ($host = 0; $host < count($hosts); $host++) { $mxhosts[$weights[$host]] = $hosts[$host]; } ksort($mxhosts); for (reset($mxhosts), $host = 0; $host < count($mxhosts); Next($mxhosts), $host++) { $hosts[$host] = $mxhosts[Key($mxhosts)]; } } else { $hosts = array(); if (strcmp(@gethostbyname($domain), $domain) != 0) { $hosts[] = $domain; } } return count($hosts) != 0; }
/** * @param Field $field * @return bool */ public function validate(Field $field) { if ($field->isValueEmpty() === true) { return true; } $fieldValue = $field->getValue(); $emailValid = filter_var($fieldValue, FILTER_VALIDATE_EMAIL); if ($emailValid === false) { return false; } if ($this->checkMx === false) { return true; } $domain = substr($fieldValue, strrpos($fieldValue, '@') + 1); $mxRecords = array(); if (getmxrr(idn_to_ascii($domain), $mxRecords) === true) { return true; } // Port 25 fallback check if there's no MX record $aRecords = dns_get_record($domain, DNS_A); if (count($aRecords) <= 0) { return false; } $connection = @fsockopen($aRecords[0]['ip'], 25); if (is_resource($connection) === true) { fclose($connection); return true; } return false; }
/** * implementation of isValidEmail by linuxjournal. * @link http://www.linuxjournal.com/article/9585?page=0,3 * @return boolean */ private function isValidEmail($email, $remoteCheck) { // check for all the non-printable codes in the standard ASCII set, // including null bytes and newlines, and exit immediately if any are found. if (preg_match("/[\\000-\\037]/", $email)) { return false; } $pattern = "/^[-_a-z0-9\\'+*\$^&%=~!?{}]++(?:\\.[-_a-z0-9\\'+*\$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\\.[a-z]{2,6}|\\d{1,3}(?:\\.\\d{1,3}){3})(?::\\d++)?\$/iD"; if (!preg_match($pattern, $email)) { return false; } if ($remoteCheck === true) { // Validate the domain exists with a DNS check // if the checks cannot be made (soft fail over to true) list($user, $domain) = explode('@', $email); if (function_exists('checkdnsrr')) { if (!checkdnsrr($domain, "MX")) { // Linux: PHP 4.3.0 and higher & Windows: PHP 5.3.0 and higher return false; } } else { if (function_exists("getmxrr")) { if (!getmxrr($domain, $mxhosts)) { return false; } } } } return true; }
function valid_email($email = '') { global $validate_mail_host; // checks proper syntax if (preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/', $email)) { if ($validate_mail_host) { // gets domain name list($username, $domain) = split('@', $email); // checks for if MX records in the DNS $mxhosts = array(); if (getmxrr($domain, $mxhosts)) { // mx records found foreach ($mxhosts as $host) { if (fsockopen($host, 25, $errno, $errstr, 7)) { return true; } } return false; } else { // no mx records, ok to check domain if (fsockopen($domain, 25, $errno, $errstr, 7)) { return true; } else { return false; } } } else { return true; } } else { return false; } }
function checkAddress($sAddress) { if (!is_valid_email_address($sAddress)) { return CA_ERROR_ADDRESS_INVALID; } /* get MX records */ $sDomain = substr($sAddress, strpos($sAddress, '@') + 1); if (getmxrr($sDomain, $mx_records, $mx_weight) == false) { $mx_records = array($sDomain); $mx_weight = array(0); } // sort MX records $mxs = array(); for ($i = 0; $i < count($mx_records); $i++) { $mxs[$i] = array('mx' => $mx_records[$i], 'prio' => $mx_weight[$i]); } usort($mxs, "mailcheck_cmp"); reset($mxs); // check address with each MX until one mailserver can be connected for ($i = 0; $i < count($mxs); $i++) { $retval = $this->pCheckAddress($sAddress, $mxs[$i]['mx']); if ($retval != CA_ERROR_CONNECT) { return $retval; } } return CA_ERROR_CONNECT; }
public static function mxconnect($host = null, $port = null, $tout = null, $name = null, $context = null, $debug = null) { global $_RESULT; $_RESULT = array(); if (!FUNC5::is_debug($debug)) { $debug = debug_backtrace(); } if (!is_string($host)) { FUNC5::trace($debug, 'invalid host type'); } else { $host = strtolower(trim($host)); if (!($host != '' && FUNC5::is_hostname($host, true, $debug))) { FUNC5::trace($debug, 'invalid host value'); } } $res = FUNC5::is_win() ? FUNC5::getmxrr_win($host, $arr, $debug) : getmxrr($host, $arr); $con = false; if ($res) { foreach ($arr as $mx) { if ($con = self::connect($mx, $port, null, null, null, $tout, $name, $context, $debug)) { break; } } } if (!$con) { $con = self::connect($host, $port, null, null, null, $tout, $name, $context, $debug); } return $con; }
protected function process() { $email = $_POST['mail_sender']; $res = null; $user = null; $domain = null; $MXHost = null; preg_match("/\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*/", $email, $res); $translator = $this->application->get('translator'); if (!$res || $res[0] !== $email || empty($email)) { $this->contactStatus = $translator->translate('mail_invalide'); } else { list($user, $domain) = explode('@', $email); if (!getmxrr($domain, $MXHost)) { $this->contactStatus = $translator->translate('mail_invalide'); } else { $mail = new Mailer(); $mail->addRecipient('*****@*****.**', ''); $mail->addFrom($email, ''); $mail->addSubject($_POST['mail_title'], ''); $mail->html = "<table><tr><td>" . utf8_decode('Identité') . " :<br/>====================</td></tr>" . "<tr><td>{$_POST['mail_sender']}<br/></td></tr>" . "<tr><td>Message :<br/>====================</td></tr>" . "<tr><td>" . nl2br(htmlspecialchars(utf8_decode($_POST['mail_message']))) . "</td></tr></table>"; if (!$mail->send()) { $this->contactStatus = $mail->errorLog(); } } } }
function get_mx($hostname) { if (strpos($hostname, '@')) { list($user, $hostname) = explode('@', $hostname); } // split hostname from email address if (function_exists('getmxrr')) { @getmxrr($hostname, $mxhosts, $mxweight); } // check for a true MX record if (isset($mxhosts) && !empty($mxhosts)) { return array_shift($mxhosts); } else { // RFC says use the A line if there is no MX $ip = gethostbyname($hostname); // get the ip from hostname if ($ip != $hostname) { // continue if returned ip not hostname $hostname = gethostbyaddr($ip); // get the rdns (real) hostname $ip = gethostbyname($hostname); // check the (real) hostname has an A record if ($ip != $hostname) { return $hostname; } // return if returned ip not hostname } } // If all else fails... return $hostname; }
function checkEmail($Email) { if (substr_count(PHP_OS, 'win') || substr_count(PHP_OS, 'Win') || substr_count(PHP_OS, 'WIN')) { function getmxrr($hostname, &$mxhosts) { $mxhosts = array(); exec('nslookup -type=mx ' . $hostname, $result_arr); foreach ($result_arr as $line) { if (preg_match("/.*mail exchanger = (.*)/", $line, $matches)) { $mxhosts[] = $matches[1]; } } return count($mxhosts) > 0; } } if (!eregi("^[a-zA-Z0-9\\_\\-\\.]+@[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-\\.]+\$", $Email)) { return false; } else { list($Username, $Domain) = split("@", $Email); if (getmxrr($Domain, $MXHost)) { return true; } else { if (fsockopen($Domain, 25, $errno, $errstr, 30)) { return true; } else { return false; } } return true; } }
function valid_email($email = "") { global $validate_mail_host; // checks proper syntax if (preg_match("/^([\\w\\!\\#\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`{\\|\\}\\~]+\\.)*[\\w\\!\\#\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`{\\|\\}\\~]+@((((([a-z0-9]{1}[a-z0-9\\-]{0,62}[a-z0-9]{1})|[a-z])\\.)+[a-z]{2,6})|(\\d{1,3}\\.){3}\\d{1,3}(\\:\\d{1,5})?)\$/i", $email)) { if ($validate_mail_host) { // gets domain name list($username, $domain) = split("@", $email); // checks for if MX records in the DNS $mxhosts = array(); if (getmxrr($domain, $mxhosts)) { // mx records found foreach ($mxhosts as $host) { if (fsockopen($host, 25, $errno, $errstr, 7)) { return true; } } return false; } else { // no mx records, ok to check domain if (fsockopen($domain, 25, $errno, $errstr, 7)) { return true; } else { return false; } } } else { return true; } } else { return false; } }
function validEmail($email, $extended = false) { if (empty($email) or !is_string($email)) { return false; } if (!preg_match('/^([a-z0-9_\'&\\.\\-\\+=])+\\@(([a-z0-9\\-])+\\.)+([a-z0-9]{2,10})+$/i', $email)) { return false; } if (!$extended) { return true; } $config = acymailing_config(); if ($config->get('email_checkpopmailclient', false)) { if (preg_match('#^.{1,5}@(gmail|yahoo|aol|hotmail|msn|ymail)#i', $email)) { return false; } } if ($config->get('email_checkdomain', false) and function_exists('getmxrr')) { $domain = substr($email, strrpos($email, '@') + 1); $mxhosts = array(); $checkDomain = getmxrr($domain, $mxhosts); if (!empty($mxhosts) && strpos($mxhosts[0], 'hostnamedoesnotexist')) { array_shift($mxhosts); } if (!$checkDomain || empty($mxhosts)) { $dns = @dns_get_record($domain, DNS_A); if (empty($dns)) { return false; } } } $object = new stdClass(); $object->IP = $this->getIP(); $object->emailAddress = $email; if ($config->get('email_botscout', false)) { $botscoutClass = new acybotscout(); $botscoutClass->apiKey = $config->get('email_botscout_key'); if (!$botscoutClass->getInfo($object)) { return false; } } if ($config->get('email_stopforumspam', false)) { $email_stopforumspam = new acystopforumspam(); if (!$email_stopforumspam->getInfo($object)) { return false; } } if ($config->get('email_iptimecheck', 0)) { $lapseTime = time() - 7200; $db = JFactory::getDBO(); $db->setQuery('SELECT COUNT(*) FROM #__acymailing_subscriber WHERE created > ' . intval($lapseTime) . ' AND ip = ' . $db->Quote($object->IP)); $nbUsers = $db->loadResult(); if ($nbUsers >= 3) { return false; } } return true; }
/** Parst eine E-Mail Adresse und prüft, ob Host existiert * * @param string $email Die zu parsende E-Mail Adresse * @return mixed Die E-Mail Adresse, falls erfolgreich, false andernfalls * @author Cédric Neukom */ function parseEmail($email) { $host = preg_replace('/^.+@(.+)$/', '$1', $email); if (getmxrr($host, $hosts)) { return $email; } else { return false; } }
/** * Sends the request to a server for validating * the existance of an email adress * @return boolean true if response was received before timeout */ public function validate($email) { if (!preg_match('/([^\\@]+)\\@(.+)$/', $email, $matches)) { return false; } $user = $matches[1]; $domain = $matches[2]; if (!function_exists('checkdnsrr')) { throw new Exception(sprintf('%s could not find function "checkdnsrr"', __CLASS__)); } if (!function_exists('getmxrr')) { throw new Exception(sprintf('%s could not find function "getmxrr"', __CLASS__)); } // Get MX Records to find smtp servers handling this domain if (getmxrr($domain, $mxhosts, $mxweight)) { for ($i = 0; $i < count($mxhosts); $i++) { $mxs[$mxhosts[$i]] = $mxweight[$i]; } asort($mxs); $mailers = array_keys($mxs); } elseif (checkdnsrr($domain, 'A')) { $mailers[0] = gethostbyname($domain); } else { return false; } // Try to send to each mailserver $total = count($mailers); $ok = false; for ($n = 0; $n < $total; $n++) { $timeout = $this->timeout; $errno = 0; $errstr = 0; $sock = @fsockopen($mailers[$n], 25, $errno, $errstr, $timeout); if (!$sock) { continue; } $response = fgets($sock); stream_set_timeout($sock, $timeout); $meta = stream_get_meta_data($sock); $cmds = array("HELO localhost", sprintf("MAIL FROM: <%s>", $this->from), "RCPT TO: <{$email}>", "QUIT"); if (!$meta['timed_out'] && !preg_match('/^2\\d\\d[ -]/', $response)) { break; } $success_ok = true; foreach ($cmds as $cmd) { fputs($sock, "{$cmd}\r\n"); $response = fgets($sock, 4096); if (!$meta['timed_out'] && preg_match('/^5\\d\\d[ -]/', $response)) { $success_ok = false; break; } } fclose($sock); return $success_ok; } return false; }
function getmxrr_portable($hostname = "", &$mxhosts, &$weight) { if (function_exists("getmxrr")) { $result = getmxrr($hostname, $mxhosts, $weight); } else { $result = getmxrr_win($hostname, $mxhosts, $weight); } return $result; }
/** * Static function that detects wether we're running windows or not and then either uses the native version of * getmxrr or the alternative one. See getmxrr_windows below for more information. * * @param hostname The host for which we want to get the mx records. * @param mxhosts The array we are going to fill with the mx records. * @return Returns either true or false. * @static */ function getmxrr($hostname, &$mxhosts) { if (OsDetect::isWindows()) { // call the alternative version return Dns::getmxrr_windows($hostname, $mxhosts); } else { // use the native version return getmxrr($hostname, $mxhosts); } }
/** * @param $host * @return bool|array */ public function query($host) { if (getmxrr($host, $mx_records, $mx_weight) === false) { $this->logger->debug("no MX records for host <{$host}> found"); return false; } $this->logger->debug("found " . count($mx_records) . " MX records for host <{$host}>"); // TODO: sort by weight return $mx_records; }
/** * Get MX records as IP addresses corresponding to a given * Internet host name sorted by weight * @param string $hostname Host name * @return array Array with IP addresses */ function getMXRecords($hostname = '') { $ips = array(); if ($hostname != '') { $records = array(); if (function_exists('getmxrr')) { // Non-Windows platform $mxhosts = null; $weights = null; if (false !== getmxrr($hostname, $mxhosts, $weights)) { // Sort MX records by weight $key_host = array(); foreach ($mxhosts as $key => $host) { if (!isset($key_host[$weights[$key]])) { $key_host[$weights[$key]] = array(); } $key_host[$weights[$key]][] = $host; } unset($weights); $records = array(); ksort($key_host); foreach ($key_host as $hosts) { foreach ($hosts as $host) { $records[] = $host; } } } } else { // Windows platform $result = shell_exec('nslookup.exe -type=MX ' . $hostname); if ($result != '') { $matches = null; if (preg_match_all("'^.*MX preference = (\\d{1,10}), mail exchanger = (.*)\$'simU", $result, $matches)) { if (!empty($matches[2])) { array_shift($matches); array_multisort($matches[0], $matches[1]); $records = $matches[1]; } } } } } // Resolve host names if (!empty($records)) { foreach ($records as $rec) { if ($resolved = gethostbynamel($rec)) { foreach ($resolved as $ip) { $ips[] = $ip; } } } } return $ips; }
function is_email($email, $use_dns = false) { if (!preg_match('/^[^\\s@]+@([a-z0-9-]+(\\.[a-z0-9-]+)+)$/i', $email, $matches)) { return false; } elseif ($use_dns) { $tmp = array(); return getmxrr($matches[1], $tmp) || dns_get_record($matches[1], DNS_A); } else { return true; } }
private function _validate_email($email) { // Create the syntactical validation regular expression $regexp = "^([_a-z0-9-]+)(\\.[_a-z0-9-]+)*@([a-z0-9-]+)(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})\$"; // Validate the syntax if (eregi($regexp, $email)) { list($username, $domaintld) = split("@", $email); // Validate the domain return getmxrr($domaintld, $mxrecords); } return false; }
/** * Validates an email address * @param string $address * @return bool $isvalid */ public function email($em, $testMXRecord = false) { if (preg_match('/^([a-zA-Z0-9\._\+-]+)\@((\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,7}|[0-9]{1,3})(\]?))$/', $em, $matches)) { if ($testMXRecord) { list($username, $domain) = split("@", $em); return getmxrr($domain, $mxrecords); } else { return true; } } else { return false; } }
function verifMail($mail) { if (preg_match('/^[a-zA-Z0-9_]+@[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-\\.]+$]/i', $mail)) { return false; } list($nom, $domaine) = explode('@', $mail); if (getmxrr($domaine, $mxhosts)) { return true; } else { return false; } }
public static function getMX($host) { if (!getmxrr($host, $mx_h, $mx_w) || count($mx_h) == 0) { return false; } $res = array(); for ($i = 0; $i < count($mx_h); $i++) { $res[$mx_h[$i]] = $mx_w[$i]; } asort($res); return $res; }
/** * Extract all MX hosts. */ public function mxHosts() { if (!$this->exists()) { return []; } $mx_hosts = $mx_weigths = []; if (!getmxrr($this->domain, $mx_hosts, $mx_weigths)) { return []; } $res = array_combine($mx_hosts, $mx_weigths); asort($res); return $res; }
public function checkMail($mail) { $result = false; list($prefix, $domain) = split("@", $mail); if (function_exists("getmxrr") && getmxrr($domain, $mxhosts)) { $result = true; } elseif (@fsockopen($domain, 25, $errno, $errstr, 5)) { $result = true; } else { $result = false; } return $result; }
/** * Checks an email adress * * @param string $email email to test * @access private * @return bool * @author Alexander Mieland * @copyright 2000-2004 by APP - Another PHP Program */ function apcms_ValidateEmail($email) { if (eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}\$", $email, $check)) { if (getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp)) { return TRUE; } if (checkdnsrr(substr(strstr($check[0], '@'), 1), "ANY")) { return TRUE; } return TRUE; } return FALSE; }
public static function is_valid_email($email, $test_mx = false) { if (eregi("^([_a-z0-9-]+)(\\.[_a-z0-9-]+)*@([a-z0-9-]+)(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})\$", $email)) { if ($test_mx) { list($username, $domain) = split("@", $email); return getmxrr($domain, $mxrecords); } else { return true; } } else { return false; } }
/** * Validates an email address * @param string $address * @return bool $isvalid */ public function email($em, $testMXRecord = false) { if (preg_match('/^([a-zA-Z0-9\\._\\+-]+)\\@((\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,7}|[0-9]{1,3})(\\]?))$/', $em, $matches)) { if ($testMXRecord && function_exists('getmxrr')) { list($username, $domain) = explode('@', $em); return getmxrr($domain, $mxrecords); } else { return true; } } else { return false; } }
/** * Prüft ob die Mail korrekt geschrieben wurde ud es die Domain für Mails * überhaupt gibt * * @version 1.0 * @author Rolf Neef rolf.neef@onlinehome.de * @param String $sMail * @return Array */ private function CheckMailAdress($sMail) { $aMxHostsAssoc = array(); if (filter_var($sMail, FILTER_VALIDATE_EMAIL) === false) { return array('success' => 'false', 'message' => 'Das ist keine gültige Mail-Adresse.'); } $aDoimanNumbers = preg_split('/@/', $sMail); getmxrr($aDoimanNumbers[1], $aMxHostsAssoc); if (empty($aMxHostsAssoc)) { return array('success' => 'false', 'message' => 'Diese Mail-Domain existiert nicht.'); } return array('success' => 'true'); }