computermax2328 Posted November 5, 2012 Share Posted November 5, 2012 Hello All, If I have a newsletter process script with name and email, is there a way to identify if the email is an email address? For example johndoe@gmail.com. I kind of want to think of a way to identify if it is a real name as well. Maybe just ask for first and last name. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/270298-if-not-email-address/ Share on other sites More sharing options...
Lukeidiot Posted November 5, 2012 Share Posted November 5, 2012 (edited) You will need to use Regex for email addresses. http://www.regular-expressions.info/email.html Edited November 5, 2012 by Lukeidiot Quote Link to comment https://forums.phpfreaks.com/topic/270298-if-not-email-address/#findComment-1390255 Share on other sites More sharing options...
trq Posted November 5, 2012 Share Posted November 5, 2012 You could use a regular expression to see if the string is in a valid email address format. It doesn't however guarantee it is an actual email address. That is why sites use email verification. If you want force your users into supplying an email address that works, you need to verify it up front. Quote Link to comment https://forums.phpfreaks.com/topic/270298-if-not-email-address/#findComment-1390256 Share on other sites More sharing options...
computermax2328 Posted November 5, 2012 Author Share Posted November 5, 2012 I looked up email validation and html5 has and input type for email. I think I am going to look into that before I look into regular expressions Quote Link to comment https://forums.phpfreaks.com/topic/270298-if-not-email-address/#findComment-1390257 Share on other sites More sharing options...
trq Posted November 5, 2012 Share Posted November 5, 2012 Client side validation always needs to be backed up by server side validation. Quote Link to comment https://forums.phpfreaks.com/topic/270298-if-not-email-address/#findComment-1390258 Share on other sites More sharing options...
computermax2328 Posted November 5, 2012 Author Share Posted November 5, 2012 Right! And it email input isn't supported by all browsers. Back to square one Quote Link to comment https://forums.phpfreaks.com/topic/270298-if-not-email-address/#findComment-1390259 Share on other sites More sharing options...
Pikachu2000 Posted November 5, 2012 Share Posted November 5, 2012 filter_var with FILTER_VALIDATE_EMAIL, and send a confirmation email that requires the user to perform a verification. Quote Link to comment https://forums.phpfreaks.com/topic/270298-if-not-email-address/#findComment-1390264 Share on other sites More sharing options...
slj90 Posted November 5, 2012 Share Posted November 5, 2012 (edited) <?php $email = $_POST['email']; if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) $error = 'Please enter a valid email address'; ?> Edited November 5, 2012 by slj90 Quote Link to comment https://forums.phpfreaks.com/topic/270298-if-not-email-address/#findComment-1390266 Share on other sites More sharing options...
computermax2328 Posted November 5, 2012 Author Share Posted November 5, 2012 (edited) They have a PHP command for everything. I love PHP! In the simplest form, something like this?? $email = $_GET['email']; if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) { echo "This is not a valid email"; } else { mail($email, "Please Validate"); } I understand there are no headers or message. Edited November 5, 2012 by computermax2328 Quote Link to comment https://forums.phpfreaks.com/topic/270298-if-not-email-address/#findComment-1390268 Share on other sites More sharing options...
JeanPierre Posted November 8, 2012 Share Posted November 8, 2012 They have a PHP command for everything. I love PHP! In the simplest form, something like this?? $email = $_GET['email']; if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) { echo "This is not a valid email"; } else { mail($email, "Please Validate"); } I understand there are no headers or message. The PHP function checks if the email address is correctly build up. But it doesn't say anything if the domain name exists. I wrote a small example, which after the PHP check also checks if the domain name exists: http://www.wmappz.com/php/validate-email-address/ Quote Link to comment https://forums.phpfreaks.com/topic/270298-if-not-email-address/#findComment-1391046 Share on other sites More sharing options...
Pikachu2000 Posted November 8, 2012 Share Posted November 8, 2012 And checking if the domain exists doesn't do anything to tell you if it's a valid address either. That's why you send a validation email to the address the user provided. Quote Link to comment https://forums.phpfreaks.com/topic/270298-if-not-email-address/#findComment-1391056 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.