smy101 Posted March 12, 2007 Share Posted March 12, 2007 OK, so I'm trying to have a script that is used as an action script for a simple HTML form. The HTML form will simply have a field to enter an email address. The HTML Form action will use "emailvalidate.php". I need for the PHP script to validate a REAL email addres. I have tried other scripts on the internet, but no luck. Upon validation, here is what I need executed: if (validation == "true") { mail( $email_list, "Thank you for registering!", $message1, "From: $me" ); header( "Location: http://www.mywebsite.com ); } else { mail( $email_list, "$username is an Invalid Email address ", $message2, "From: $me" ); header( "Location: http://www.mywebsite.com" ); }; So upon validation, if the email is valid, it will send Message A to the email in question, me and a third party. If it is invalid, it will instead send Message B to me and a third party stating the email was invalid. I would like for the validation to be as extensive as possible, while remaining functional for ALL email addresses. I've noticed some validation is very extensive, but will only work for pop3 addresses. So I guess I just want to be thorough while remaining inclusive to all addresses. Thanks in advance! ??? Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 12, 2007 Share Posted March 12, 2007 You wont us to do all that for free look in the regex section of the forum then goto php.net for a proper email code snippet ok. then try your self then come and ask ok nicely? Quote Link to comment Share on other sites More sharing options...
smy101 Posted March 12, 2007 Author Share Posted March 12, 2007 You wont us to do all that for free look in the regex section of the forum then goto php.net for a proper email code snippet ok. then try your self then come and ask ok nicely? Forget to take your Midol today? All I asked for was some help finding the right script. I didnt ask you to write the whole thing for me. A point in the right direction would have been sufficient. I searched the forums here and elsewhere and found several similar topics, but none specific enough for what I needed. I also DID try to do it myself and obviously that didn't work either or I wouldn't be here asking for HELP in the PHP HELP FORUM! Also, I did ask "nicely," as even the title says "PLEASE!" I think you need a nap. For anyone else out there not feeling like a jerk tonight, here is where I tried to start from, using this script, but to no avail. Most of the script came from here: http://www.zend.com/zend/spotlight/ev12apr.php <?php $Name = $_REQUEST['Name']; $Email = $_REQUEST['Email']; $currentdate = date("F j, Y, g:i a"); $message1 = "This is my message!"; $message2 = "Email address given is invalid!"; $me = "myemail@myemail.com"; function ValidateMail($Email) { global $HTTP_HOST; $result = array(); if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)) { $result[0]=false; $result[1]="$Email is not properly formatted"; return $result; } list ( $Username, $Domain ) = split ("@",$Email); if (getmxrr($Domain, $MXHost)) { $ConnectAddress = $MXHost[0]; } else { $ConnectAddress = $Domain; } $Connect = fsockopen ( $ConnectAddress, 25 ); if ($Connect) { if (ereg("^220", $Out = fgets($Connect, 1024))) { fputs ($Connect, "HELO $HTTP_HOST\r\n"); $Out = fgets ( $Connect, 1024 ); fputs ($Connect, "MAIL FROM: <{$Email}>\r\n"); $From = fgets ( $Connect, 1024 ); fputs ($Connect, "RCPT TO: <{$Email}>\r\n"); $To = fgets ($Connect, 1024); fputs ($Connect, "QUIT\r\n"); fclose($Connect); if (!ereg ("^250", $From) || !ereg ( "^250", $To )) { $result[0]=false; $result[1]="Server rejected address"; return $result; } } else { $result[0] = false; $result[1] = "No response from server"; return $result; } } else { $result[0]=false; $result[1]="Can not connect E-Mail server."; return $result; } $result[0]=true; $result[1]="$Email appears to be valid."; return $result; } // end of function if ($result == "$Email appears to be valid.") { mail( $email_list, "Thank you for registering!", $message1, "From: $me" ); header( "Location: http://www.mywebsite.com ); } else { mail( $email_list, "$username is an Invalid Email address ", $message2, "From: $me" ); header( "Location: http://www.mywebsite.com" ); }; Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 12, 2007 Share Posted March 12, 2007 Post ur form and i do it for you ok. that is correct what wrong with that code look's good to me what does it not do m8. Quote Link to comment Share on other sites More sharing options...
interpim Posted March 12, 2007 Share Posted March 12, 2007 I think what Redarrow is suggesting is, to write a script you think will work, be it off of a tutorial or someone else's validation script... then if you are having problems with that post back here with the symptoms you are having with that script and any errors it may be giving you. Then we can go through and help you fix that code. Everyone here can use google just the same as you, except we want you to try. Quote Link to comment Share on other sites More sharing options...
smy101 Posted March 12, 2007 Author Share Posted March 12, 2007 Post ur form and i do it for you ok. that is correct what wrong with that code look's good to me what does it not do mate. It executes as though the email address were invalid EVERYTIME even when testing with a valid email address. Quote Link to comment Share on other sites More sharing options...
smy101 Posted March 12, 2007 Author Share Posted March 12, 2007 I think what Redarrow is suggesting is, to write a script you think will work, be it off of a tutorial or someone else's validation script... then if you are having problems with that post back here with the symptoms you are having with that script and any errors it may be giving you. Then we can go through and help you fix that code. Everyone here can use google just the same as you, except we want you to try. I know what he meant, but he could have approached it a little better considering this is a HELP forum. The guy acted like I asked him to mow my lawn and paint my house. Quote Link to comment Share on other sites More sharing options...
interpim Posted March 12, 2007 Share Posted March 12, 2007 well... my lawn could use a mow too... how about it Redarrow? Quote Link to comment Share on other sites More sharing options...
smy101 Posted March 12, 2007 Author Share Posted March 12, 2007 well... my lawn could use a mow too... how about it Redarrow? I'm sorry, did you come here to help or taunt me? Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted March 12, 2007 Share Posted March 12, 2007 Nice shots Guys..... Ok i also face this problem before,i was searching for better regex. But then i find ... It is: if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)){ Echo "Invalid e-mail address"; } Its nice and working fine. Try this one and let me know it works or not. Quote Link to comment Share on other sites More sharing options...
smy101 Posted March 12, 2007 Author Share Posted March 12, 2007 Nice shots Guys..... Ok i also face this problem before,i was searching for better regex. But then i find ... It is: if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)){ Echo "Invalid e-mail address"; } Its nice and working fine. Try this one and let me know it works or not. Are you saying to replace that line in my code, or only use that snippet instead? B/C that doesn't validate very thoroughly alone and I Also don't see how to execute the next part of my script if I leave it at that. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted March 12, 2007 Share Posted March 12, 2007 Nice shots Guys..... Ok i also face this problem before,i was searching for better regex. But then i find ... It is: if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)){ Echo "Invalid e-mail address"; } Its nice and working fine. Try this one and let me know it works or not. Are you saying to replace that line in my code, or only use that snippet instead? B/C that doesn't validate very thoroughly alone and I Also don't see how to execute the next part of my script if I leave it at that. Thanks for your help. Replace this: if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)) { $result[0]=false; $result[1]="$Email is not properly formatted"; return $result; } To this: if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $Email)){ Echo "Invalid e-mail address"; } I put echo here it will give up the error with ease. Quote Link to comment Share on other sites More sharing options...
smy101 Posted March 12, 2007 Author Share Posted March 12, 2007 Nice shots Guys..... Ok i also face this problem before,i was searching for better regex. But then i find ... It is: if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)){ Echo "Invalid e-mail address"; } Its nice and working fine. Try this one and let me know it works or not. Are you saying to replace that line in my code, or only use that snippet instead? B/C that doesn't validate very thoroughly alone and I Also don't see how to execute the next part of my script if I leave it at that. Thanks for your help. Replace this: if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)) { $result[0]=false; $result[1]="$Email is not properly formatted"; return $result; } To this: if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $Email)){ Echo "Invalid e-mail address"; } I put echo here it will give up the error with ease. I don't really need it to echo the error, though. I need it to completely execute the script and mail message A if its valid or message B if its invalid. I'm confused. Thanks again! Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 12, 2007 Share Posted March 12, 2007 <?php $message_friend=($_POST['message_friend']); $subject_friend=($_POST['subject_friend']); $email_friend=($_POST['email_friend']); $date=date("d-m-y"); if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email_friend)){ echo "<b><center><font color='red'>Please try agin your email is incorrect!</font></b>"; } if($_POST['submit']){ $to = $email_friend; $subject = $subject_friend; $message = $message_friend; $headers = "From: server@barnyard.com\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; // Send if(@mail($to, $subject, $message, $headers)){ echo "<h3> Email Sent....</h3><center><br>Email: $to<br><br>Date Sent: $date<br><br>Subject: <br>$subject<br><br>Message Sent:<br> $message<br><br></center>"; exit; }else{ echo"<b><center><font color='red' > Sorry Email: $to not Sent ..............</font></center></b>"; } } ?> <center> <h1>Please Use This Page To Email A Friend</h1> <br> <form method="POST" action=""> <br> <b><font color="red">Enter Email Subject</font></b> <br> <input type="text" name="subject_friend"> <br> <br> <textarea name='message_friend' cols="40" rows="15"></textarea> <br> <br> <b><font color="red">Enter Email Address</font></b> <br> <input type="text" name="email_friend"> <br> <br> <br> <input type="submit" name="submit" value="SEND"> </form> </center> Quote Link to comment Share on other sites More sharing options...
smy101 Posted March 12, 2007 Author Share Posted March 12, 2007 <?php $message_friend=($_POST['message_friend']); $subject_friend=($_POST['subject_friend']); $email_friend=($_POST['email_friend']); $date=date("d-m-y"); if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email_friend)){ echo "<b><center><font color='red'>Please try agin your email is incorrect!</font></b>"; } if($_POST['submit']){ $to = $email_friend; $subject = $subject_friend; $message = $message_friend; $headers = "From: server@barnyard.com\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; // Send if(@mail($to, $subject, $message, $headers)){ echo "<h3> Email Sent....</h3><center><br>Email: $to<br><br>Date Sent: $date<br><br>Subject: <br>$subject<br><br>Message Sent:<br> $message<br><br></center>"; exit; }else{ echo"<b><center><font color='red' > Sorry Email: $to not Sent ..............</font></center></b>"; } } ?> <center> <h1>Please Use This Page To Email A Friend</h1> <br> <form method="POST" action=""> <br> <b><font color="red">Enter Email Subject</font></b> <br> <input type="text" name="subject_friend"> <br> <br> <textarea name='message_friend' cols="40" rows="15"></textarea> <br> <br> <b><font color="red">Enter Email Address</font></b> <br> <input type="text" name="email_friend"> <br> <br> <br> <input type="submit" name="submit" value="SEND"> </form> </center> Thanks, but again I don't need it to echo the error so that I can see it upon Submission. I need it to completely execute the script and mail message A if its valid or message B if its invalid. I do not want to see an error or a confirmation when I click "Submit." I want it to fully execute the script and if it's an invalid email, I want to get an email stating that it was invalid. Also, the above script you use is just a simple validation method, right? It only checks to see if an email address is in proper format - correct? I need something to also check the domain and see if the domain and even the email address itself is valid with the domain. Thanks again for your help. Quote Link to comment Share on other sites More sharing options...
smy101 Posted March 13, 2007 Author Share Posted March 13, 2007 Can anyone else help me with this problem? Thanks! Quote Link to comment Share on other sites More sharing options...
smy101 Posted March 14, 2007 Author Share Posted March 14, 2007 *bump* Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.