NickG21 Posted December 21, 2006 Share Posted December 21, 2006 hey everyone. below is my code for a basic validation script with a CheckEmail function that is supposed to try and access the domain server used in order to assure that the e-mail address being used is a valid e-mail. the context seemed alright to me, but i am unsure of the variables and if they need to be declared in other areas to specifiy the information being sent. here are the codes and the errorsany help/tutorials are greatly appreciatedthank youErrors:Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in .../emailserver.php on line 15Warning: fsockopen(): unable to connect to nick.edu:25 in .../emailserver.php on line 15Code:[code]<?phpfunction checkEmail($email){ if (!preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $email)) { return false; }list($Username, $Domain) = split("@",$email);if(getmxrr($Domain, $MXHost)) { return TRUE;}else { if(fsockopen($Domain, 25, $errno, $errstr, 30)) { return TRUE; } else { return FALSE; }}}if (isset($_POST['submit'])) { $email = $_POST['email']; $name = $_POST['text1']; $number = $_POST['text2']; $error = array(); // check e-mail address // display success or failure message if (!preg_match("/^([a-zA-Z])+/",$name)){ $error[] = "Your Name May Only Contain Letters"; $name="";} if (!preg_match("/^([0-9])+/",$number)){ $error[] = "Invalid ZipCode"; $number=""; } if (CheckEmail($email) == FALSE) { $error[] = "Invalid E-Mail Address"; $email=""; } if (count($error)>0) { $msg = "<p class=\"error\"><big><b>The Following Errors Were Found, Please Re-Enter:</b></big><br/>". implode('<br />', $error). "</p>"; } else { $msg = "<p><b>Thank You, Your Information Has Been Accepted</b></p>"; }}echo isset($msg) ? $msg : '';?>[/code] Link to comment https://forums.phpfreaks.com/topic/31526-e-mail-server-validation/ Share on other sites More sharing options...
alpine Posted December 21, 2006 Share Posted December 21, 2006 Check out the users contribution notes in the manual for some examples:http://no.php.net/manual/en/function.getmxrr.phpYou could however add error surpressing on the fsockopen to prevent errors during check, if the domain is unavailable (false) the error msg will print out on this part.[code]@fsockopen($Domain, 25, $errno, $errstr, 30)[/code] Link to comment https://forums.phpfreaks.com/topic/31526-e-mail-server-validation/#findComment-146126 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.