public function testUseValidationCode()
 {
     $gateway = new ValidationCodeGateway();
     $email = '*****@*****.**';
     $validationCode = 'test vcode';
     $gateway->insertValidationCode($email, $validationCode);
     $gateway->useValidationCode($email, $validationCode);
 }
<?php

include_once 'Net/SMTP.php';
include_once 'Mail.php';
include_once '../DAL/ValidationCodeGateway.php';
$password = $_POST['password'];
$names = $_POST['names'];
$emails = $_POST['emails'];
$msg = $_POST['msg'];
$gateway = new ValidationCodeGateway();
if ($password != 'Evgeny') {
    die('Invalid Password');
}
echo "Validation codes are sent to following addresses: <br/>";
$i = -1;
foreach ($emails as $email) {
    $i++;
    if (empty($email)) {
        continue;
    }
    $validationCode = generateValidationCode(15);
    $gateway->insertValidationCode($email, $validationCode);
    $vars = array("@@name@@", "@@email@@", "@@validationCode@@");
    $vals = array($names[$i], $email, $validationCode);
    $newMsg = str_replace($vars, $vals, $msg);
    sendValidationCode($email, $validationCode, $newMsg);
    echo "{$email} <br/>";
}
function generateValidationCode($length)
{
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
function register_check_errors($username, $email, $password, $password2, $validationCode)
{
    global $main_smarty;
    require_once mnminclude . 'check_behind_proxy.php';
    $userip = check_ip_behind_proxy();
    if (is_ip_banned($userip)) {
        $form_username_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_YourIpIsBanned');
        $error = true;
    }
    if (!isset($username) || strlen($username) < 3) {
        // if no username was given or username is less than 3 characters
        $form_username_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_UserTooShort');
        $error = true;
    }
    if (preg_match('/\\pL/u', 'a')) {
        // Check if PCRE was compiled with UTF-8 support
        if (!preg_match('/^[_\\-\\d\\p{L}\\p{M}]+$/iu', $username)) {
            // if username contains invalid characters
            $form_username_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_UserInvalid');
            $error = true;
        }
    } else {
        if (!preg_match('/^[^~`@%&=\\/;:\\.,<>!"\\\'\\^\\.\\[\\]\\$\\(\\)\\|\\*\\+\\-\\?\\{\\}\\\\]+$/', $username)) {
            $form_username_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_UserInvalid');
            $error = true;
        }
    }
    if (user_exists(trim($username))) {
        // if username already exists
        $form_username_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_UserExists');
        $error = true;
    }
    if (!check_email(trim($email))) {
        // if email is not valid
        $form_email_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_BadEmail');
        $error = true;
    }
    if (email_exists(trim($email))) {
        // if email already exists
        $form_email_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_EmailExists');
        $error = true;
    }
    if (strlen($password) < 5) {
        // if password is less than 5 characters
        $form_password_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_FiveCharPass');
        $error = true;
    }
    if ($password !== $password2) {
        // if both passwords do not match
        $form_password_error[] = $main_smarty->get_config_vars('PLIGG_Visual_Register_Error_NoPassMatch');
        $error = true;
    }
    $vars = array('username' => $username, 'email' => $email, 'password' => $password);
    check_actions('register_check_errors', $vars);
    if ($vars['error'] == true) {
        $error = true;
        if ($vars['username_error']) {
            $form_username_error[] = $vars['username_error'];
        }
        if ($vars['email_error']) {
            $form_email_error[] = $vars['email_error'];
        }
        if ($vars['password_error']) {
            $form_password_error[] = $vars['password_error'];
        }
    }
    $gateway = new ValidationCodeGateway();
    if (!$error && $gateway->isValidationCodeUnsed($email, $validationCode)) {
        $gateway->useValidationCode($email, $validationCode);
    } else {
        $error = true;
        $main_smarty->assign('form_validationCode_error', 'Validation code is invalid, please contact admin to acquire a valid code.');
    }
    $main_smarty->assign('form_username_error', $form_username_error);
    $main_smarty->assign('form_email_error', $form_email_error);
    $main_smarty->assign('form_password_error', $form_password_error);
    return $error;
}