Ticket System in PHP - #3 Email Validation

Introduction:

This tutorial is the third part on how to create a ticket system in PHP. This ticket system allows for more secured reset password options, and other complex or private data exchange on a community website.

Previous HTML:

The current HTML we have for this process is the password reset form, found below:
  1. <form action='reset.php' method='POST'>
  2. <input type='password' placeholder='Password' name='password1' />
  3. <input type='password' placeholder='Password2' name='password2' />
  4. <input type='submit' value='Reset Password' name='resetPassword' />
  5. </form>

Forgot Password Email Generation:

The only thing we need to start this process of creating a new forgot password ticket is the email address to which we want to send the newly generated ticket to. This email address would be linked with the customer's account. But again, since I don't have a specific login form, I am just going to add an 'enter email' form on to my 'reset.php' page found above containing the HTML we have already created.
  1. <form action='reset.php' method='GET'>
  2. <input type='text' placeholder='Email address' name='email' />
  3. <input type='submit' value='Send Reset Email' name='emailButton' />
  4. </form>
Now whenever this form is used, it will send the entered email address to the page 'reset.php' via the method GET.

Processing:

The next thing we are going to do is validate the email address. Then in the next tutorial we will be generating the new ticket, adding it to the database, linking it to the user's account/record, and sending the ticket ID/Text/Number to the entered email address. Validation. First we check that the email address is longer than five characters...
  1. if (isSet($_GET['email'])) {
  2. $email = $_GET['email'];
  3. if (strlen($email) > 5) {
  4.  
  5. }else
  6. echo 'Email too short!';
  7. }
Next we can check that the email address contains an @ symbol...
  1. if (strpos('@', $email) !== FALSE) {
  2.  
  3. }else
  4. echo 'Email doesn\'t contain an @ symbol! Invalid.';
And, finally we can check that the email address entered contains a dot...
  1. if (strpos('.', $email) !== FALSE) {
  2.  
  3. }else
  4. echo 'Email doesn\'t contain a . symbol! Invalid.';

Finished!

Add new comment