Jump to content

Email Structure Reader?


justlukeyou

Recommended Posts

Hi,

 

I'm trying to use a script which reads the structure of email such as 'something@website.com'.

 

My code currently accepts 'anything'.

 

I've tried using this:

 

http://www.w3schools.com/php/php_secure_mail.asp

 

And the following code. Is there a preferred way of reading and varifying an email?

 

  <div class="registerinputright"> 
	    <input class="field" type="text" name="email"  type="text" width="600" value="<?php echo htmlspecialchars($registerEmail); ?>" /> 
	    <?php if($errors['registerEmail']) print '<div class="invalid">' . $errors['registerEmail'] . '</div>'; ?> 

Link to comment
Share on other sites

Thanks,

 

Whats the part on here which filters emails http://uk3.php.net/filter_var

 

Should it be something like this? UserEmail is the email the user enters.

 

 <?php filter_var('userEmail', (FILTER_VALIDATE_EMAIL)); ?>

 

I still struggle understand a word of the PHP site but now Im just working on the details of membership script. The structure is there.

Link to comment
Share on other sites

Right, sorted it. However I have to errors. One if the email box is blank and one if the email address is not a valid structure.

 

How do I make it so that if the email box is blank only the first error appears?

 

 if(!isset($registerEmail) || empty($registerEmail)) {
    $errors['registerEmail1'] = "Please enter your email address.";
   }

$email = "$registerEmail";
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
 {
    $errors['registerEmail'] = "Please enter your email address in a valid format.  Example: bobsmith@companyname.com";
 }
else
 {
    $errors['registerEmail'] = "E-mail is valid";
 }

Link to comment
Share on other sites

There are a couple of ways, but the most basic would be to change the second if to an elseif (also, your making life harder for yourself the way you are assigning $email, have a look):

if(!isset($registerEmail) || empty(trim($registerEmail))) {
$errors['registerEmail1'] = "Please enter your email address.";
}
elseif(!filter_var($regiserEmail, FILTER_VALIDATE_EMAIL) {
$errors['registerEmail'] = "Please enter your email address in a valid format. Example: bobsmith@companyname.com";
}
else {
$errors['registerEmail'] = "E-mail is valid";
}

Edited by Muddy_Funster
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.