Пример #1
0
<?php

class emailValidation
{
    public function displayPage()
    {
        echo "<!DOCTYPE html>\n\t\t<head>\n\t\t<title>Email Validator</title>\n\t\t<meta http-equiv='Content-Type' content='text/html;charset=utf-8'/>\n\t\t<link href='css/styles.css' rel='stylesheet' />\n\t\t</head>\n\t\t<body>\n\t\t\t<div>\n\t\t\t<h1>Please type in your email address</h1>\n\t\t\t\t<form id='unit' method='post' action='index.php'>\n\n\t\t\t\t\t<!--type='email' does client side validation\n\t\t\t\t\t\tnot sure what required does-->\n\n\t\t\t\t\t<input type='email' name='email' placeholder='Example: your_name@gmail.com' required>\n\t\t\t\t\t<input type='submit' name='submit' value='Go!'>\n\t\t\t\t\t<br>\n\t\t\t\t</form>\n\t\t\t</div>\n\t\t</body>\n\t\t</html>";
        if (isset($_POST['submit'])) {
            $email = $_POST['email'];
            // does server side validation but doesn't
            // run because client side validation blocks it
            if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
                echo "<br>" . $email . " is a valid address</div>";
            } else {
                echo "<br>" . $email . " is not valid. Try again.";
            }
        }
    }
}
$isEmailValid = new emailValidation();
$isEmailValid->displayPage();
Пример #2
0
 /**
  * Method to validate one ore more email addresses
  *
  * @access	public
  *
  * @param	array   $cid            Subscriber/Test-recipient IDs
  * @param   boolean $showProgress
  * @return	array   $res            associative array of result data
  */
 public function validate_mail($cid = array(), $showProgress = false)
 {
     $_db = $this->_db;
     $query = $_db->getQuery(true);
     $config = Jfactory::getConfig();
     $validator = new emailValidation();
     $tmp = explode('@', $config->get('mailfrom'));
     $mailuser = $tmp[0];
     $mailserver = $tmp[1];
     $validator->timeout = 5;
     $validator->data_timeout = 0;
     $validator->localuser = $mailuser;
     $validator->localhost = $mailserver;
     $validator->debug = 0;
     $validator->html_debug = 1;
     $validator->exclude_address = "";
     $query->select('*');
     $query->from($_db->quoteName('#__bwpostman_subscribers'));
     $query->where($_db->quoteName('id') . ' IN (' . implode(',', $cid) . ')');
     //		$query->order($_db->escape($listOrdering).' '.$listDirn);
     $_db->setQuery($query);
     $subscribers = $_db->loadObjectList();
     // After the validation process we want to show the results
     // --> therefore we store the results into an array
     $res = array();
     $i = 0;
     foreach ($subscribers as $subscriber) {
         if ($showProgress) {
             echo "\n<br>{$subscriber->email} ... ";
             ob_flush();
             flush();
         }
         $res[$i]['id'] = $subscriber->id;
         $res[$i]['email'] = $subscriber->email;
         $res[$i]['name'] = $subscriber->name;
         $res[$i]['firstname'] = $subscriber->firstname;
         // Skip confirmed email address if they still passed the confirmation process and where identified as invalid
         if (strstr($subscriber->name, 'INVALID_')) {
             // Skipped
             $res[$i]['result'] = 2;
             $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATION_SKIPPED');
             $i++;
             if ($showProgress) {
                 echo JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATION_SKIPPED');
                 ob_flush();
                 flush();
             }
             continue;
         }
         $result = $validator->ValidateEmailBox($subscriber->email);
         if ($result === -1) {
             // Unable to validate the address with this host
             $res[$i]['result'] = -1;
             $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_HOST');
             $i++;
             if ($showProgress) {
                 echo JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_HOST');
                 ob_flush();
                 flush();
             }
         } elseif ($result) {
             // The host is able to receive email. The address could be valid.
             $res[$i]['result'] = 1;
             $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_VALIDATING_EMAIL');
             $i++;
             if ($showProgress) {
                 echo JText::_('COM_BWPOSTMAN_SUB_VALIDATING_EMAIL');
                 ob_flush();
                 flush();
             }
             // Activate this account
             $date = JFactory::getDate();
             $time = $date->toSql();
             $user = JFactory::getUser();
             $query = $_db->getQuery(true);
             $query->update($_db->quoteName('#__bwpostman_subscribers'));
             $query->set($_db->quoteName('status') . " = " . (int) 1);
             $query->set($_db->quoteName('confirmation_date') . " = " . $_db->Quote($time, false));
             $query->set($_db->quoteName('confirmed_by') . " = " . (int) $user->get('id'));
             $query->where($_db->quoteName('id') . ' = ' . (int) $subscriber->id);
             $_db->setQuery($query);
             if (!$_db->query()) {
                 $this->setError($_db->getErrorMsg());
                 return false;
             }
         } else {
             // The host can\'t receive email or this mailbox doesn\'t exist. The address is NOT valid.
             $res[$i]['result'] = 0;
             $res[$i]['result_txt'] = JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_EMAIL');
             $i++;
             if ($showProgress) {
                 echo JText::_('COM_BWPOSTMAN_SUB_ERROR_VALIDATING_EMAIL');
                 ob_flush();
                 flush();
             }
             // Prepend an INVALID_ to the subscriber name
             $query = $_db->getQuery(true);
             $query->update($_db->quoteName('#__bwpostman_subscribers'));
             $query->set($_db->quoteName('name') . " = " . $_db->Quote('INVALID_' . $subscriber->name));
             $query->where($_db->quoteName('id') . ' = ' . (int) $subscriber->id);
             $_db->setQuery($query);
             if (!$_db->query()) {
                 $this->setError($_db->getErrorMsg());
                 return false;
             }
         }
     }
     return $res;
 }