tadakan Posted May 16, 2008 Share Posted May 16, 2008 Ok, so I'm a huge php newbie and I've been teaching myself html, css and javascript over the last month or so as well, so I'm not sure if the problem I'm having is with my html form or with my php, but hopefully somebody will spot the problem, because it's driving me nuts. I found and modified a php script to send an email to a specific address based on user input in a form. It's going to be combined with some other stuff and eventually it will insert the name and email address in to an existing mssql database. The emailing part of the script works just fine by itself, but I got a little ambitious and decided that it would be a good idea to add an email validation function that I saw while I was surfing around. Basically the idea is that if the function validates the email address it just sends the email and navigates to a page that I tell it to (right now it goes back to the test html page.) But if there's a typo(lack of an @, etc) it'll show a page telling the user that the address is wrong and to please go back and correct it. When I try it with my own email address however, tadakan@(domain=gmail.com) properly formatted of course, it throws it back calling it invalid. Now here's the code: (the email validation function is from this http://www.ilovejackdaniels.com/php/email-address-validation/ website. I'll reply back with my html. It's really messy, but it's just a test that will eventually be incorporated in to another page. <?php function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } if (check_email_address($email)) { // construct message $name = $_POST['name']; $email = $_POST['email']; $truemessage .= "Name: " . $name . "\n"; $truemessage .= "Email: " . $email . "\n"; $headers = 'From: ' . $email . "\n" . 'Reply-To: ' . $email . "\n" . 'X-Mailer: PHP/' . phpversion(); mail('[email protected]', 'Message from your Website', $truemessage, $headers); // redirect back to url visitor came from header("Location: test02.html"); } else { print("<HTML><BODY>Sorry, this does not appear to be a valid email address! Please go back and try again."); print("</BODY></HTML>"); } ?> Link to comment https://forums.phpfreaks.com/topic/105851-send-email-email-validation-script-with-html-form/ Share on other sites More sharing options...
tadakan Posted May 16, 2008 Author Share Posted May 16, 2008 and here's my form. Thanks so much in advance for any help! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!-- Generated by VCOM Technology V5.0. For information please visit: http://www.v-com.com --> <HTML> <HEAD> <TITLE> Schedule </TITLE> <META NAME="Author" CONTENT="Internet Professionals, LLC" /> <SCRIPT LANGUAGE="JavaScript"><!--// IE=(navigator.appName.indexOf('Microsoft') >= 0); NS=(navigator.appName.indexOf('Netscape') >= 0); V4=(parseInt(navigator.appVersion) >= 4); V5=(parseInt(navigator.appVersion)>=5); V5=(V5||navigator.appVersion.indexOf("MSIE 5")!=-1); V5=(V5||navigator.appVersion.indexOf("MSIE 6")!=-1); MAC=(navigator.userAgent.indexOf('Mac')!=-1); //--> </SCRIPT> <style type="text/css"> <!-- .style1 { font-size: 12pt; font-weight: bold; } --> </style> </HEAD> <BODY BGCOLOR="#670001" TEXT="#000000" LINK="#693520" VLINK="#c49351" ALINK="#FF0000" onLoad="if(V4) OnWeLoad()" onResize="OnWeResize()"> <DIV STYLE="position:absolute;left:0;top:0;width:870;height:186;"></DIV> <div STYLE="position:absolute; left:4px; top:2px; width:256px; font-family:'Arial',sans-serif; font-size:8pt; color: #670001;"> <table width="274" border="0" cellspacing="1" bordercolor="#ffffff" bgcolor="#670001" > <form action="contact.php" method="post" name="form1" class="style2"> <tr> <td colspan="4" align="center" class="style3"><span class="style1"><font color="#fff8db">Sign Up for our mailing list and receive access to our weekly conference call!</font></span></td> </tr> <tr> <td> </td> <td width="87"><div align="left" class="style3"><font color="#ffffff">Name</font></div></td> <td width="172"><input type="text" name="name" id="name" size="28" /></td> <td width="1"> </td> </tr> <tr> <td> </td> <td width="87"><div align="left" class="style3"><font color="#ffffff">E-mail</font></div></td> <td width="172"><input type="text" name="email" id="email" size="28" /></td> <td width="1"> </td> </tr> <tr> <td> </td> <td colspan="2"><input type="submit" name="button" id="button" value="Sign up!"></td> <td> </td> </tr> </form> </table> </div> </BODY> </HTML> Link to comment https://forums.phpfreaks.com/topic/105851-send-email-email-validation-script-with-html-form/#findComment-542509 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.