static function checkEmail($email) { $f3 = \Base::instance(); if (filter_var($email, FILTER_VALIDATE_EMAIL)) { include_once '../vendor/smtp_validateemail/smtp_validateEmail.php'; $SMTP_Validator = new \SMTP_validateEmail(); $SMTP_Validator->debug = $f3->get('DEBUG') == 3 ? true : false; // do the validation $results = $SMTP_Validator->validate(array($email), $f3->get('email.admin')); if ($f3->get('DEBUG') > 0) { $f3->dump($results); } return $results[$email]; } else { return false; } }
<?php /** * Example 1 * Validate a single Email via SMTP */ // include SMTP Email Validation Class require_once 'smtp_validateEmail.class.php'; // the email to validate $email = '*****@*****.**'; // an optional sender $sender = '*****@*****.**'; // instantiate the class $SMTP_Validator = new SMTP_validateEmail(); // turn on debugging if you want to view the SMTP transaction $SMTP_Validator->debug = true; // do the validation $results = $SMTP_Validator->validate(array($email), $sender); // view results echo $email . ' is ' . ($results[$email] ? 'valid' : 'invalid') . "\n"; // // send email? // if ($results[$email]) { // //mail($email, 'Confirm Email', 'Please reply to this email to confirm', 'From:'.$sender."\r\n"); // send email // } else { // echo 'The email addresses you entered is not valid'; // }
public function validatePostResult() { $postData = $this->getPostData(); if (Mage::registry('webforms_errors_flag_' . $this->getId())) { return Mage::registry('webforms_errors_' . $this->getId()); } $errors = array(); // check captcha if ($this->useCaptcha()) { if (Mage::app()->getRequest()->getPost('recaptcha_response_field')) { $verify = Mage::helper('webforms')->getCaptcha()->verify(Mage::app()->getRequest()->getPost('recaptcha_challenge_field'), Mage::app()->getRequest()->getPost('recaptcha_response_field')); if (!$verify->isValid()) { $errors[] = Mage::helper('webforms')->__('Verification code was not correct. Please try again.'); } } else { $errors[] = Mage::helper('webforms')->__('Verification code was not correct. Please try again.'); } } // check honeypot captcha if (Mage::getStoreConfig('webforms/honeypot/enable')) { if (Mage::app()->getRequest()->getPost('message')) { $errors[] = Mage::helper('webforms')->__('Spam bot detected. Honeypot field should be empty.'); } } // check custom validation $logic_rules = $this->getLogic(); $fields_to_fieldsets = $this->getFieldsToFieldsets(); foreach ($fields_to_fieldsets as $fieldset_id => $fieldset) { foreach ($fieldset['fields'] as $field) { if ($field->getIsActive() && $field->getValidateRegex() && $field->getRequired()) { $pattern = $field->getValidateRegex(); $status = @preg_match($pattern, "Test"); if (false === $status) { $pattern = "/" . $pattern . "/"; } $validate = new Zend_Validate_Regex($pattern); foreach ($this->getPostData() as $key => $value) { if ($key == $field->getId() && !$validate->isValid($value)) { $errors[] = $field->getName() . ": " . $field->getValidateMessage(); } } } $hint = htmlspecialchars(trim($field->getHint())); if ($field->getRequired() && is_array($this->getPostData())) { foreach ($this->getPostData() as $key => $value) { if ($key == $field->getId() && $field->getType() == 'textarea') { // check profanity $target_field = array("id" => 'field_' . $field->getId(), 'logic_visibility' => $field->getData('logic_visibility')); $target_fieldset = array("id" => 'fieldset_' . $fieldset_id, 'logic_visibility' => $fieldset['logic_visibility']); $profanity = $this->is_profanity($value); if ((trim($value) != $hint || trim($value) != '') && $profanity) { $errors[] = Mage::helper('webforms')->__('%s is required', $field->getName()); } } if ($key == $field->getId() && $field->getType() != 'select/checkbox' && (trim($value) == $hint || trim($value) == '')) { // check logic visibility $target_field = array("id" => 'field_' . $field->getId(), 'logic_visibility' => $field->getData('logic_visibility')); $target_fieldset = array("id" => 'fieldset_' . $fieldset_id, 'logic_visibility' => $fieldset['logic_visibility']); if ($this->getLogicTargetVisibility($target_field, $logic_rules, $this->getPostData()) && $this->getLogicTargetVisibility($target_fieldset, $logic_rules, $this->getPostData())) { $errors[] = Mage::helper('webforms')->__('%s is required', $field->getName()); } } } } // check if the e-mail address is valid if ($this->getEmailSmtpValidation()) { if ($field->getIsActive() && $field->getType() == 'email') { if (!empty($postData[$field->getId()])) { $smtp_validate = new SMTP_validateEmail(); $smtp_validate_results = $smtp_validate->validate(array($postData[$field->getId()]), Mage::getStoreConfig('trans_email/ident_general/email')); if (!$smtp_validate_results[$postData[$field->getId()]]) { $errors[] = Mage::helper('webforms')->__('E-mail address does not seem to exist: %s', $postData[$field->getId()]); } } } } // check e-mail stoplist if ($field->getIsActive() && $field->getType() == 'email') { if (!empty($postData[$field->getId()])) { if (stristr(Mage::getStoreConfig('webforms/email/stoplist'), $postData[$field->getId()])) { $errors[] = Mage::helper('webforms')->__('E-mail address is blocked: %s', $postData[$field->getId()]); } } } } } // check files $files = $this->getUploadedFiles(); foreach ($files as $field_name => $file) { if (isset($file['name']) && file_exists($file['tmp_name'])) { $field_id = str_replace('file_', '', $field_name); $postData['field'][$field_id] = Varien_File_Uploader::getCorrectFileName($file['name']); $field = Mage::getModel('webforms/fields')->setStoreId($this->getStoreId())->load($field_id); $filesize = round($file['size'] / 1024); $images_upload_limit = Mage::getStoreConfig('webforms/images/upload_limit'); if ($this->getImagesUploadLimit() > 0) { $images_upload_limit = $this->getImagesUploadLimit(); } $files_upload_limit = Mage::getStoreConfig('webforms/files/upload_limit'); if ($this->getFilesUploadLimit() > 0) { $files_upload_limit = $this->getFilesUploadLimit(); } if ($field->getType() == 'image') { // check file size if ($filesize > $images_upload_limit && $images_upload_limit > 0) { $errors[] = Mage::helper('webforms')->__('Uploaded image %s (%s kB) exceeds allowed limit: %s kB', $file['name'], $filesize, $images_upload_limit); } // check that file is valid image if (!@getimagesize($file['tmp_name'])) { $errors[] = Mage::helper('webforms')->__('Unsupported image compression: %s', $file['name']); } } else { // check file size if ($filesize > $files_upload_limit && $files_upload_limit > 0) { $errors[] = Mage::helper('webforms')->__('Uploaded file %s (%s kB) exceeds allowed limit: %s kB', $file['name'], $filesize, $files_upload_limit); } } $allowed_extensions = $field->getAllowedExtensions(); // check for allowed extensions if (count($allowed_extensions)) { preg_match("/\\.([^\\.]+)\$/", $file['name'], $matches); $file_ext = strtolower($matches[1]); // check file extension if (!in_array($file_ext, $allowed_extensions)) { $errors[] = Mage::helper('webforms')->__('Uploaded file %s has none of allowed extensions: %s', $file['name'], implode(', ', $allowed_extensions)); } } // check for valid filename if (Mage::getStoreConfig('webforms/files/validate_filename') && !preg_match("/^[a-zA-Z0-9_\\s-\\.]+\$/", $file['name'])) { $errors[] = Mage::helper('webforms')->__('Uploaded file %s has non-latin characters in the name', $file['name']); } } } $validate = new Varien_Object(array('errors' => $errors)); Mage::dispatchEvent('webforms_validate_post_result', array('webform' => $this, 'validate' => $validate)); Mage::register('webforms_errors_flag_' . $this->getId(), true); Mage::register('webforms_errors_' . $this->getId(), $validate->getData('errors')); return $validate->getData('errors'); }
<?php /** * Example 2 * Validate a single Email via SMTP */ // include SMTP Email Validation Class require_once 'smtp_validateEmail.class.php'; // the email to validate $emails = array('*****@*****.**', '*****@*****.**'); // an optional sender $sender = '*****@*****.**'; // instantiate the class $SMTP_Validator = new SMTP_validateEmail(); // turn on debugging if you want to view the SMTP transaction $SMTP_Validator->debug = true; // do the validation $results = $SMTP_Validator->validate($emails, $sender); // view results foreach ($results as $email => $result) { // send email? if ($result) { //mail($email, 'Confirm Email', 'Please reply to this email to confirm', 'From:'.$sender."\r\n"); // send email } else { echo 'The email address ' . $email . ' is not valid'; } }
/** * Validate email based on user settings. * * First, verify email using `is_email()` WordPress function (required) * * Then, process email validation based on settings. * * @param KWSContact $Contact Contact object * * @return WP_Error|boolean|void If valid, return `true`, otherwise return a WP_Error object. */ function validateEmail(KWSContact &$Contact) { if (!class_exists('DataValidation')) { include_once CTCT_DIR_PATH . 'lib/class.datavalidation.php'; } if (!class_exists('SMTP_validateEmail')) { include_once CTCT_DIR_PATH . 'lib/mail/smtp_validateEmail.class.php'; } $email = $Contact->get('email'); $is_valid = array(); // 1: Check if it's an email at all if (empty($email)) { do_action('ctct_activity', 'Empty email address', $email); $this->errors[] = new WP_Error('empty_email', __('Please enter your email address.', 'ctct'), 'email_address'); return; } elseif (!is_email($email)) { do_action('ctct_activity', 'Invalid email address', $email); $this->errors[] = new WP_Error('not_email', __('Invalid email address.', 'ctct'), 'email_address'); return; } $methods = (array) CTCT_Settings::get('spam_methods'); // 2: Akismet validation if (in_array('akismet', $methods)) { $akismetCheck = $this->akismetCheck($Contact); if (is_wp_error($akismetCheck)) { $this->errors[] = $akismetCheck; return; } } // 3: WangGuard validation if (in_array('wangguard', $methods) && function_exists('wangguard_verify_email') && wangguard_server_connectivity_ok()) { global $wangguard_api_host; // If WangGuard isn't set up yet, set'er up! if (empty($wangguard_api_host)) { wangguard_init(); } $return = wangguard_verify_email($email, wangguard_getRemoteIP(), wangguard_getRemoteProxyIP()); if ($return == 'checked' || $return == 'not-checked') { do_action('ctct_activity', 'WangGuard validation passed.', $email, $return); } else { $this->errors[] = new WP_Error('wangguard', __('Email validation failed.', 'ctct'), $email, $return); return; } } // 4: DataValidation.com validation if (in_array('datavalidation', $methods) && class_exists('DataValidation')) { $Validate = new DataValidation(CTCT_Settings::get('datavalidation_api_key')); $validation = $Validate->validate($email); $process_inconclusive = apply_filters('ctct_process_inconclusive_emails', true); if (is_wp_error($validation)) { do_action('ctct_activity', 'DataValidation.com error', 'The email was not processed because of the error: ' . $validation->get_error_message()); return; } elseif ($validation === false || $validation === NULL && !$process_inconclusive) { do_action('ctct_activity', 'DataValidation validation failed.', $email, $Validate); $message = isset($Validate->message) ? $Validate->message : __('Not a valid email.', 'ctct'); $this->errors[] = new WP_Error('datavalidation', $message, $email, $Validate); return; } if ($validation === NULL) { do_action('ctct_activity', 'DataValidation validation inconclusive.', $email, $Validate); } elseif ($validation === true) { do_action('ctct_activity', 'DataValidation validation passed.', $email, $Validate); } } // 5: SMTP validation if (in_array('smtp', $methods) && class_exists('SMTP_validateEmail')) { try { $SMTP_Validator = new SMTP_validateEmail(); // Timeout after 1 second $SMTP_Validator->max_conn_time = 1; $SMTP_Validator->max_read_time = 1; $SMTP_Validator->debug = 0; // Prevent PHP notices about timeouts ob_start(); $results = $SMTP_Validator->validate(array($email), get_option('admin_email')); ob_clean(); if (isset($results[$email])) { // True = passed if ($results[$email]) { do_action('ctct_activity', 'SMTP validation passed.', $email, $results); return true; } else { do_action('ctct_activity', 'SMTP validation failed.', $email, $results); $this->errors[] = new WP_Error('smtp', __('Email validation failed.', 'ctct'), $email, $results); return false; } } else { do_action('ctct_activity', 'SMTP validation did not work', 'Returned empty results. Maybe it timed out?'); return true; } } catch (Exception $e) { do_action('ctct_error', 'SMTP validation broke.', $e); return; } } return true; }
function _valid_home() { global $user, $style; /* // the email to validate $email = '*****@*****.**'; // an optional sender $sender = '*****@*****.**'; // instantiate the class $SMTP_Valid = new SMTP_validateEmail(); // do the validation $result = $SMTP_Valid->validate($email, $sender); // view results var_dump($result); echo $email.' is '.($result ? 'valid' : 'invalid')."\n"; // send email? if ($result) { //mail(...); } */ include(XFS . 'core/smtpvalidate.php'); $SMTP_Valid = new SMTP_validateEmail(); $sql = 'SELECT * FROM _email WHERE email_active = 1 LIMIT 1'; if (!$email = sql_fieldrow($sql)) { $this->e('No queue emails.'); } $sql = 'SELECT * FROM ?? ORDER BY address_id LIMIT ??, ??'; $members = sql_rowset(sql_filter($sql, $email['email_data'], $email['email_last'], $email['email_batch'])); $i = 0; foreach ($members as $row) { if (!preg_match('/^[a-z0-9\.\-_\+]+@[a-z0-9\-_]+\.([a-z0-9\-_]+\.)*?[a-z]+$/is', $row['address_account'])) { continue; } $result = $SMTP_Valid->validate($row['address_account'], '*****@*****.**'); // view results echo '<pre>'; var_dump($result); echo '</pre>'; flush(); sleep(1); $i++; } exit; return; }
function cron_validate_newsletter_address() { global $config; require_once $config["homedir"] . "/include/smtp_validate_email.php"; $smtp_validate = new SMTP_validateEmail(); $sql = "SELECT email FROM tnewsletter_address WHERE status = 0 AND validated = 0 LIMIT " . $config["batch_email_validation"]; $newsletter_emails = get_db_all_rows_sql($sql); if ($newsletter_emails === false) { return; } $i = 0; foreach ($newsletter_emails as $email) { $news_emails[$i] = $email['email']; $i++; } $checked_emails = $smtp_validate->validate($news_emails); foreach ($news_emails as $mail) { $exists = array_key_exists($mail, $checked_emails); if (!$exists) { $checked_emails[$mail] = false; } } foreach ($checked_emails as $email => $validated) { if ($validated) { //validated $values['validated'] = 1; $values['status'] = 0; } else { //disabled/removed $values['validated'] = 1; $values['status'] = 1; } process_sql_update('tnewsletter_address', $values, array('email' => $email)); } return; }
function mailControl2($validemail) { require_once 'smtp_validateEmail.class.php'; // doğrulanacak email $emails = array('*****@*****.**', '*****@*****.**'); // sorgu atacak email. //noreply@floracicek.com $sender = '*****@*****.**'; $SMTP_Validator = new SMTP_validateEmail(); $SMTP_Validator->debug = true; // valdiation $results = $SMTP_Validator->validate(array($emails), $sender); // sonuç foreach ($results as $email => $result) { // send email? if ($result) { //mail($email, 'Confirm Email', 'Please reply to this email to confirm', 'From:'.$sender."\r\n"); // send email } else { echo 'The email address ' . $email . ' is not valid'; } } }
function checkRealEmail($email) { /** $array = json_decode(file_get_contents("http://verify-email.org/api.html?format=raw&usr=vaodiemm&pwd=lucnap&check=$email")); if($array['verify_status'] == '1'){ return true; } return false; **/ if (ENVIRONMENT == PYRO_DEVELOPMENT) { return true; } else { require_once "./asset/SMTP_validateEmail.php"; $SMTP = new SMTP_validateEmail(); $array = $SMTP->validate(array($email), '*****@*****.**'); if (getValueOfArray($array) == 1) { return true; } return false; } }
<?php require_once "smtpvalidateclass.php"; // the email to validate $email = '*****@*****.**'; // an optional sender $sender = '*****@*****.**'; // instantiate the class $SMTP_Valid = new SMTP_validateEmail(); // do the validation $result = $SMTP_Valid->validate($email, $sender); // view results var_dump($result); echo $email . ' is ' . ($result ? 'valid' : 'invalid') . "\n"; // send email? if ($result) { //mail(...); } ?>