Jump to content

E-mail Address Checker


JimKI

Recommended Posts

I need to add a e-mail address checker to my form where do I add this in my form? and is this the correct e-mail validation code?e-mail checker code:function checkEmail($email) {if (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)*.([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email)) {return false;}else{$record = 'MX';list($user,$domain) = split('@',$email);if(!checkdnsrr($domain,$record)){return false;}else{return true;}}}Form Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><META NAME="robots" CONTENT="noindex,nofollow"><link href="../../../styles/_e-learning.css" rel="stylesheet" type="text/css" /></head><body background="images/background.jpg"><div id="container" align="center"><a name="result"></a><div id="header"><p class="tenTitle">Exercise 1a: 10 Great Reasons To Be In Business</p></div><div id="main"><?php/* fix IE Error with a browser opening inside another browser that has sessions('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); */ // SET VARIABLES AND ARRAYS $stepNumber = '1a'; $numQuestions = '10'; $questions = array(1 => '1. Be your own boss', '2. Ability to set your own hours and working conditions', '3. Hard work directly benefits you and your business', '4. Undertaking an exciting new venture', '5. Control over earning and growth potential', '6. Unlimited opportunities to challenge yourself and learn', '7. Chance to be creative and take risks', '8. Ability to fully use your skills, knowledge, and talent', '9. Desire financial independence', '10. Ability to work in the industry/field of your choice' ); $numOptions = 5; $options = array(1 => 'Strongly Agree', 'Agree', 'Neutral', 'Disagree', 'Strongly Disagree' ); // IF FORM WAS FILLED OUT, CALCULATE SCORE, ELSE SCORE EQUALS 0 $score[] = 0; for ($i = 1; $i <= $numQuestions; $i++) { if(isset($_POST['radio'.$i])){ if ($options[$_POST['radio'.$i]] == $options[1]) { $score[$i] = 5; } elseif ($options[$_POST['radio'.$i]] == $options[2]) { $score[$i] = 4; } elseif ($options[$_POST['radio'.$i]] == $options[3]) { $score[$i] = 3; } elseif ($options[$_POST['radio'.$i]] == $options[4]) { $score[$i] = 2; } else { $score[$i] = 1; } } else { $score[$i] = 0; } } // UNIQUE TO FIRST SESSION OF EACH STEP $_SESSION['totalScore'] = 0; // ADD QEUSTIONS AND ANSWERS TO $EMAIL_BODY AND $EMAIL_BODYCC BELOW // IF FORM WAS SUBMITTED, MOVE ON TO NEXT STEP (ERROR CHECKING) if(isset($_POST['submit'])) { // CHECK FOR MISSING DATA (ERROR CHECKING) for ($i = 1; $i <= $numQuestions; $i++) { if (empty($_POST['radio'.$i])) { $problem = TRUE; $dataSpan[$i] = '<span style="color:red; font-weight:bold;">'.$questions[$i].'</span>'; } else { $dataSpan[$i] = $questions[$i]; } } if (empty($_POST['email']) && check_email_address($_POST['email'])) { $problem = TRUE; $emailSpan = '<span style="color:red; font-weight:bold;">*Your email address</span>'; } else { $emailSpan = '*Your email address'; } if (empty($_POST['emailCC']) && check_email_address($_POST['emailCC']) && (empty($_POST['name']))) { $problem = TRUE; $nameSpan = '<span style="color:red; font-weight:bold;">Your Name</span>'; } else { $nameSpan = 'Your Name'; } // IF MISSING DATA, PREPARE TO DISPLAY FORM. IF NO MISSING DATA, MOVE ON TO NEXT STEP (THANK YOU, SEND EMAILS AND LINK TO NEXT FORM) if ($problem == TRUE) { $display = TRUE; } else { $display = FALSE; } } // IF THE FORM IS NOT BEING SUBMITTED (FIRST VISIT TO PAGE), SET THE // FORM DISPLAY VARIABLE TO TRUE AND DEFINE VALUES OF DATA#SPAN VARIABLES (QUESTIONS) else { $display = TRUE; for ($i = 1; $i <= $numQuestions; $i++) { $dataSpan[$i] = $questions[$i]; } $emailSpan = '*Your email address'; $nameSpan = 'Your Name'; } if ($display == TRUE) { print '<p><strong>Instructions</strong>: Below are some of the attitudes and desires that many successful entrepreneurs possess. Read the list carefully. Think about how each of the statements relate to you - your ideas, desires, motivations, and areas of comfort or discomfort. In this exercise, quickly check each category with the answer that best relates to you, then go back and think about each - perhaps you might change your mind with this further refection - you can always come back later and change your answer.</p>'; if ($problem == TRUE) { print '<p>Please fill in questions marked in <span style="color:red; font-weight:bold;">red</p>'; } print '<div id="tenForm"> <form action="ten_steps_'.$stepNumber.'.html#result" method="POST" > <table border="0" cellpadding="4" cellspacing="3">'; for ($i = 1; $i <= $numQuestions; $i++) { echo '<tr> <td align="left" valign="top" border="0" class="submitCell"> <p>'.$dataSpan[$i].'</p>'; for ($j = 1; $j <= $numOptions; $j++) { $elemID = "radio" . $i . "_" . $j; $elemName = "radio" . $i; $chk = ""; if(isset($_POST[$elemName])) { if($_POST[$elemName] == ((string) $j)) { $chk = "CHECKED"; } } echo "<input type=\"radio\" id=\"$elemID\" name=\"$elemName\" $chk value=\"$j\">$options[$j]\n"; } print '</td> </tr>'; } print '</table><table border="0" cellpadding="3" cellspacing="2" align="center"> <tr> <td align="left" valign="top" border="0">'; print '</th> </tr> <tr> <td align="left" valign="top" border="0"> Submitting the form (* = required) </th> </tr> <tr> <td class="submitCell"> '.$emailSpan.'<br /> (to receive a copy of this form)<br /> <input type="text" size="40" maxlength="100" name="email" value="'.$_POST['email'].'" /> </td> </tr> <tr> <td class="submitCell"> Send Copy To eMentor<br /> <input type="text" size="40" maxlength="100" name="emailCc" value="'.$_POST['emailCc'].'" /> </td> </tr> <tr> <td class="submitCell"> '.$nameSpan.'<br /> (*required if sending a copy)<br /> <input type="text" size="40" maxlength="100" name="name" value="'.$_POST['name'].'" /> </td> </tr> <tr> <td class="submitCell" align="center"> <input type="reset" value="Clear" /> <input type="submit" name="submit" value="Submit" /><br /> <a href="'.$filePathState.'about_privacy.html" target="_blank"><span style="font-size:9px;">View our privacy policy</span></a> </td> </tr></table></form></div>'; } else { // DEFINE SESSION VARIABLES $_SESSION['email']=$_POST['email']; $_SESSION['emailCc']=$_POST['emailCc']; $_SESSION['name']=$_POST['name']; $_SESSION['score'.$stepNumber]=array_sum($score); $_SESSION['totalScore'] = $_SESSION['totalScore'] + $_SESSION['score'.$stepNumber]; // DEFINE VARIABLES FOR MAILING TO USER AND BUZGATE $to = 'askbuz@buzgate.org,'.$_POST['email']; $email_subject = "Your Results: 10 Great Reasons To Be In Business"; for ($i = 1; $i <= $numQuestions; $i++) { $eBodyQuestions .= $questions[$i]."\n" .$options[$_POST[radio.$i]]."\n\n"; } $email_body = $eBodyQuestions."Score: ".array_sum($score)."\n INTERPRETING THE SCORE:\n Score of 34-50: High Match\n Score of 21-35: Medium Match\n Score of 0-20: Low Match\n Total Score: ".$_SESSION['totalScore']."\n\n"; $headers = "From:".$_POST['email']; //PLACE VARIABLES IN MAIL FUNCTION mail($to, $email_subject, $email_body, $headers); // DEFINE VARIABLES FOR MAILING TO USER AND BUZGATE $toCc = $_POST['emailCc']; $email_subjectCc = "Your Results: 10 Great Reasons To Be In Business from ".$_POST['name']; $email_bodyCc = $_POST['name']." has sent this to you from www.BUZGate.org/8.0/".$state_abbrv_low."/".$page_name."\n Please contact us at askbuz@buzgate.org if you have received this in error.\n\n"; $email_bodyCc = $email_bodyCc.$email_body; $headersCc = "From:askbuz@buzgate.org"; //PLACE VARIABLES IN CC MAIL FUNCTION mail($toCc, $email_subjectCc, $email_bodyCc, $headersCc); // DISPLAY RESPONSE TO CORRECTLY FILLING OUT FORM echo "<p class='textCenter' >Thank you ".$_POST['name']." for completing Step ".$stepNumber."</p> <p class='textCenter'>Your Step ".$stepNumber." Score: ".$_SESSION['score'.$stepNumber]."<br /> Your Total Score: ".$_SESSION['totalScore']."</p>"; include ($filePath.'/inc2/tenScores.html'); echo "To proceed to the next exercise, select the <img src='../../../../e-learning2/images/grey-play-arrow.png' alt='Play' /> on the horizontal navigation bar below this view.</p>" ; }?></div> <div id="footer"></div></div></body></html>

Link to comment
Share on other sites

what exactly are you checking for? An email address existing, that it validate with an @ and .xxx? A lookup on the domain name itself?

Link to comment
Share on other sites

what exactly are you checking for? An email address existing, that it validate with an @ and .xxx? A lookup on the domain name itself?
Both
Link to comment
Share on other sites

well, you can use string functions to check to see if it contains an @ and ., and that are at least 2-3 characters after the .If you want to make sure that its in particular format and not just @.xxx, then you would want to use regex. You could probably find lots of email verfication functions in that vein on google.As far as the domain name lookup, you could test that the domain exists, but not necessarily that that specific email address exists though.

Link to comment
Share on other sites

well, you can use string functions to check to see if it contains an @ and ., and that are at least 2-3 characters after the .If you want to make sure that its in particular format and not just @.xxx, then you would want to use regex. You could probably find lots of email verfication functions in that vein on google.As far as the domain name lookup, you could test that the domain exists, but not necessarily that that specific email address exists though.
So is this code no good and not work with my form if I knew were I placed it?function checkEmail($email) {if (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)*.([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email)) {return false;}else{$record = 'MX';list($user,$domain) = split('@',$email);if(!checkdnsrr($domain,$record)){return false;}else{return true;}}}
Link to comment
Share on other sites

sorry, I didn't realize you had the actual code and were just looking to implement it into your setup......You in your code you are calling a check_email_address function. Just change/substitute the names.

Link to comment
Share on other sites

sorry, I didn't realize you had the actual code and were just looking to implement it into your setup......You in your code you are calling a check_email_address function. Just change/substitute the names.
where does it go though and do i change the checkEmail to check_email_address or vise versa
Link to comment
Share on other sites

For me this function works fine.

function emailCheck($m=""){	if (preg_match("/([a-zA-Z0-9_-]*)(@)([a-zA-Z0-9_-]*)(\.)[a-zA-Z0-9]{2,}/", $m))	{		return true;	}	else	{		return false;	}}

Link to comment
Share on other sites

where does it go though and do i change the checkEmail to check_email_address or vise versa
same difference, like I was saying. The names just have to match. You can put the code at the top of the page if you want.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...