NickG21 Posted December 27, 2006 Share Posted December 27, 2006 hey everyone, below is my code for the syntax and server validation of an e-mail address. it is a simple form with one text box for the info and a submit button, however the code isn't executing correctly and when i initially open the page there is the invalid e-mail error displayed on the top. could anyone tell me what exactly is wrong with my syntax here?thank you[code]<?phpfunction checkEmail($email){ if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+([a-zA-Z0-9\._-] +)+$/" , $email)) {return false;}list($username,$domain) = split('@',$email);$mxhosts = array();if(!getmcxrr($domain, $mxhosts)) { if(!fsockopen($domain, 25, $errno, $errstr, 30)) { return false; }else{ foreach($mxhosts as $host) {if (fsockopen($host,25,$errno,$errstr,30)) {return true;}}return false;}}if(!fsockopen($domain,25,$errno,$errstr,30)) {return false;}else{return true;}}$email = trim($_POST['email']); if(!checkEmail($email)) { echo 'Invalid email address!'; } else { echo 'Email address is valid'; }if (isset($_POST['submit'])) {$email = $_POST['email'];}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><form method="post" action="emailcheck.php"><table class="qForm"><tr><td><a>Email:</a></td><td><input type="text" size="28" name=email value-<? echo"$email"?>"><br/></td></tr><tr><input type="hidden" value="1"<td><input type="submit" name="submit" value="submit"></td></tr></table></form></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/31977-solved-unsure-syntax/ Share on other sites More sharing options...
kenrbnsn Posted December 27, 2006 Share Posted December 27, 2006 You should only do the email check if the form has been submitted.Change this:[code]<?php$email = trim($_POST['email']); if(!checkEmail($email)) { echo 'Invalid email address!'; } else { echo 'Email address is valid'; }if (isset($_POST['submit'])) {$email = $_POST['email'];}?>[/code]to[code]<?phpif (isset($_POST['submit'])) { $email = trim($_POST['email']); if(!checkEmail($email)) echo 'Invalid email address!'; else echo 'Email address is valid';}?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/31977-solved-unsure-syntax/#findComment-148391 Share on other sites More sharing options...
NickG21 Posted December 27, 2006 Author Share Posted December 27, 2006 sorry about that, rookie mistake, but the code still doesn't process the e-mail string and return if it is valid or not? any idea where i am going wrong there? Link to comment https://forums.phpfreaks.com/topic/31977-solved-unsure-syntax/#findComment-148394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.