I've configured a new vps with Ubuntu 18.04 and now want to transfer websites running on my old vps running Ubuntu 14.04.6 LTS (GNU/Linux 3.13.0-153-generic x86_64). I have a functions include for checking email addresses - see below I have installed PEAR Validate and Mail packages. I call the function with: $email=$_POST['email']; if(!emailaddresscheck($email)){ $error[]="Your email address appears to be invalid.."; } I have tried replacing occurrences of eregi with preg_match() Any guidance on how to adapt the code to run with PHP 7.2 would be very much appreciated. dbg1991 ##################################################### Code: <?php #check for format and domain existence using PEAR - returns true or false function emailcheck($email){ require_once 'Validate.php'; if (Validate::email($email, array('check_domain' => 'true'))) { return true; }else{ return false; } } # formats string for html output - returns string formatted function formatting(&$string){ $string=htmlspecialchars($string, ENT_QUOTES ); $string=str_ireplace("\r","",$string); $string=str_ireplace("\n","<br />",$string); $string=str_ireplace("","<strong>",$string); $string=str_ireplace("[eb]","</strong>",$string); $string=stripslashes($string); $string=str_replace("'","´",$string); $string=str_ireplace("[l]","<span class=\"large\">",$string); $string=str_ireplace("[el]","</span>",$string); } # formats HTML strings for text email output - returns string formatted function emailformat(&$string){ $string=str_ireplace("<b>","",$string); $string=str_ireplace("</b>","",$string); $string=str_ireplace("<strong>","",$string); $string=str_ireplace("</strong>","",$string); $string=str_ireplace("<br />","\n",$string); $string=str_replace("´","'",$string); } # checks for email address in correct form and to valid domain - returns true or flase function emailaddresscheck($emailaddress){ $validemailaddress="^[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$%&_-])*" ."@[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$%&_-])*$"; if(!eregi($validemailaddress,$emailaddress)){return false;} list($username, $maildomain)=split("@", $emailaddress); if(checkdnsrr($maildomain,"MX")){return true;} return false; } function myCheckDNSRR($hostName, $recType = '') { if(!empty($hostName)) { if( $recType == '' ) $recType = "MX"; exec("nslookup -type=$recType $hostName", $result); // check each line to find the one that starts with the host // name. If it exists then the function succeeded. foreach ($result as $line) { if(eregi("^$hostName",$line)) { return true; } } // otherwise there was no mail handler for the domain return false; } return false; } ?>
Please use [ code ]your code[ /code ] without the space inside the bracket, otherwise we can't read your code properly.
OK I think I've fixed it. After much head scratching I've come up with: Code: <?php #check for format and domain existence function emailchecker($email){ $findme="@"; $pos=strpos($email, $findme); if(!$pos){ return false; }else{ $parts = explode("@",$email); $username = $parts[1]; $username = "$username."; if(!checkdnsrr ( $username , "MX" )){ return false; }else{ return true; } } } ////////////Function call//////////////////////////////////////////////// //$email=""; //$return=emailchecker($email); //if(!$return){ //echo "<p>$email probably false $return </p>"; //}else{ //echo "<p>$email seems OK</p>"; //} ///////////////////////////////////////////////////////////////////////////// # formats string for html output - returns string formatted function formatting(&$string){ $string=htmlspecialchars($string, ENT_QUOTES ); $string=str_ireplace("\r","",$string); $string=str_ireplace("\n","<br />",$string); $string=str_ireplace("[b]","<strong>",$string); $string=str_ireplace("[eb]","</strong>",$string); $string=stripslashes($string); $string=str_replace("'","´",$string); $string=str_ireplace("[l]","<span class=\"large\">",$string); $string=str_ireplace("[el]","</span>",$string); } # formats HTML strings for text email output - returns string formatted function emailformat(&$string){ $string=str_ireplace("<b>","",$string); $string=str_ireplace("</b>","",$string); $string=str_ireplace("<strong>","",$string); $string=str_ireplace("</strong>","",$string); $string=str_ireplace("<br />","\n",$string); $string=str_replace("´","'",$string); } ?>