Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Email Validation with TowerData

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 07-05-2010, 11:26 AM
 
exsecror exsecror is offline
 

X-Wizard
  
Join Date: Apr 2007
Posts: 1,284
 

Default Email Validation with TowerData

One of the most annoying problems when practicing online commerce is when customers either mistype their email address or decide they want to provide a fake one (which in later turns to them complaining they never get any contact from the company about their order).

In order to try and reduce/prevent the problem from occurring we implemented TowerData's Email Validation Service into X-Cart to try and curb the problem. I have decided to share the code with others on the X-Cart forum but be aware you must have a TowerData account in order to use this code, you can read more about the service here:

http://www.towerdata.com/services/web/email_validation.html

Please note that the code included in this thread does not implement TowerData's multiple email address results return (to give them a drop down) or phone number validation (we saw no reason to pay for this service). If you want to implement the return of multiple email address results you're on your own for that.

---------------------------------------------------------------------------------------------

Note: You must be running a recent PHP5 release and have the soap extension installed or this will not work.

Disclaimer: I am not responsible for any site outages incurred by implementation of this code. It is your responsibility to appropriately test it on a development environment before deploying it to production and I am not available for technical support outside this thread. Also note that if TowerData is down this function will simply suppress itself quietly and allow your site to continue to operate.

---------------------------------------------------------------------------------------------

Step 1: Edit include/func/func.mail.php

We must first add a function called func_towerdata_validate() to the bottom of include/func/func.mail.php:

PHP Code:
function func_towerdata_validate($email) {
  try {
    
$client = new SoapClient('https://soap.towerdata.com/validate.wsdl',
                             array(
'trace'   => 1,
                                   
'timeout' => 10));

    
$params = array('login'                  => 'username',
                    
'password'               => 'password',
                    
'version'                => '1.2',
                    
'email_validation_level' => 4,
                    
'correct_emails'         => 'true',
                    
'max_email_corrections'  => 1,
                    
'Records'                => array('Record' => array('email' => $email)));

    
$result $client->Validate($params);
    
$code   $result->Records->Record->email->status->code;

    switch ((int)
$code) {
      case 
5:
      case 
10:
      case 
20:
      case 
30:
      case 
40:
      case 
50:
        return 
true;
        break;
      default:
        return 
false;
        break;
    }
  }
  catch (
SoapFault $fault) { return true; }


Step 2: Modify func_check_email()

The next step is to add func_towerdata_validate() to func_check_email() so that it's used during account creation and anywhere else you use func_check_email().

This step requires significant modifications to the function however and I will provide two different examples. One using the original X-Cart code and another one using filter_var() if you have the filter extension available.

Version 1: X-Cart Original Code
PHP Code:
function func_check_email($email) {
    
$email_regular_expression func_email_validation_regexp();

    if (!
preg_match('/' $email_regular_expression '/Di'stripslashes($email)))
        return 
false;

    if (!
func_towerdata_validate($email))
        return 
false;

    return 
true;


Version 2: Using the filter_var() function
PHP Code:
function func_check_email($email) {
  
/* Check Format */
  
if (!filter_var(filter_var(stripslashes($email), FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL)) {
    return 
false;
  }

  
/* Check Existance */
  
if (!func_towerdata_validate($email)) {
    return 
false;
  }

  return 
true;


Note: Remember, Version 2 only works if you have the filter extension installed!

I hope this is of good use to other users out there in curbing email problems.
Reply With Quote
  #2  
Old 07-05-2010, 01:51 PM
 
Nadeem Nadeem is offline
 

Advanced Member
  
Join Date: Sep 2006
Posts: 56
 

Default Re: Email Validation with TowerData

Thanks ! very nice
__________________
X-Cart 4.4.5 | Linux/Apache | PHP 5.2.17 | MySQL 5.0.77 | FireFox
Reply With Quote
  #3  
Old 10-21-2010, 05:50 AM
 
Jeremy Smith Jeremy Smith is offline
 

Senior Member
  
Join Date: Jan 2009
Posts: 167
 

Question Re: Email Validation with TowerData

Does this work with v4.1.11?
__________________
Version 4.1.11 on Linux (Fedora)
X-Cart Gold
Reply With Quote
  #4  
Old 02-20-2015, 12:44 AM
 
buywink buywink is offline
 

Advanced Member
  
Join Date: Apr 2012
Posts: 93
 

Default Re: Email Validation with TowerData

Quote:
Originally Posted by exsecror
One of the most annoying problems when practicing online commerce is when customers either mistype their email address or decide they want to provide a fake one (which in later turns to them complaining they never get any contact from the company about their order).

In order to try and reduce/prevent the problem from occurring we implemented TowerData's Email Validation Service into X-Cart to try and curb the problem. I have decided to share the code with others on the X-Cart forum but be aware you must have a TowerData account in order to use this code, you can read more about the service here:

http://www.towerdata.com/services/web/email_validation.html

Please note that the code included in this thread does not implement TowerData's multiple email address results return (to give them a drop down) or phone number validation (we saw no reason to pay for this service). If you want to implement the return of multiple email address results you're on your own for that.

---------------------------------------------------------------------------------------------

Note: You must be running a recent PHP5 release and have the soap extension installed or this will not work.

Disclaimer: I am not responsible for any site outages incurred by implementation of this code. It is your responsibility to appropriately test it on a development environment before deploying it to production and I am not available for technical support outside this thread. Also note that if TowerData is down this function will simply suppress itself quietly and allow your site to continue to operate.

---------------------------------------------------------------------------------------------

Step 1: Edit include/func/func.mail.php

We must first add a function called func_towerdata_validate() to the bottom of include/func/func.mail.php:

PHP Code:
function func_towerdata_validate($email) {
  try {
    
$client = new SoapClient('https://soap.towerdata.com/validate.wsdl',
                             array(
'trace'   => 1,
                                   
'timeout' => 10));

    
$params = array('login'                  => 'username',
                    
'password'               => 'password',
                    
'version'                => '1.2',
                    
'email_validation_level' => 4,
                    
'correct_emails'         => 'true',
                    
'max_email_corrections'  => 1,
                    
'Records'                => array('Record' => array('email' => $email)));

    
$result $client->Validate($params);
    
$code   $result->Records->Record->email->status->code;

    switch ((int)
$code) {
      case 
5:
      case 
10:
      case 
20:
      case 
30:
      case 
40:
      case 
50:
        return 
true;
        break;
      default:
        return 
false;
        break;
    }
  }
  catch (
SoapFault $fault) { return true; }


Step 2: Modify func_check_email()

The next step is to add func_towerdata_validate() to func_check_email() so that it's used during account creation and anywhere else you use func_check_email().

This step requires significant modifications to the function however and I will provide two different examples. One using the original X-Cart code and another one using filter_var() if you have the filter extension available.

Version 1: X-Cart Original Code
PHP Code:
function func_check_email($email) {
    
$email_regular_expression func_email_validation_regexp();

    if (!
preg_match('/' $email_regular_expression '/Di'stripslashes($email)))
        return 
false;

    if (!
func_towerdata_validate($email))
        return 
false;

    return 
true;


Version 2: Using the filter_var() function
PHP Code:
function func_check_email($email) {
  
/* Check Format */
  
if (!filter_var(filter_var(stripslashes($email), FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL)) {
    return 
false;
  }

  
/* Check Existance */
  
if (!func_towerdata_validate($email)) {
    return 
false;
  }

  return 
true;


Note: Remember, Version 2 only works if you have the filter extension installed!

I hope this is of good use to other users out there in curbing email problems.

Thank you for your code.Will it work on x-cart 4.6.1
__________________
x-cart Gold 4.4.5
Reply With Quote
  #5  
Old 02-22-2015, 06:26 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Email Validation with TowerData

Quote:
Originally Posted by buywink
Thank you for your code.Will it work on x-cart 4.6.1
Not likely, this code is almost 5 years old! But it is probable that you can work your way through it as an example. In general, the code changes between versions is enough of a difference to make you avoid just dropping it in place as is. It needs to be carefully re-integrated, and tested along the way.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #6  
Old 02-23-2015, 08:27 PM
 
buywink buywink is offline
 

Advanced Member
  
Join Date: Apr 2012
Posts: 93
 

Default Re: Email Validation with TowerData

Quote:
Originally Posted by totaltec
Not likely, this code is almost 5 years old! But it is probable that you can work your way through it as an example. In general, the code changes between versions is enough of a difference to make you avoid just dropping it in place as is. It needs to be carefully re-integrated, and tested along the way.

Thank you very much for your reply.Can you please provide me 4.6.1 specific code?

Thanks again.
__________________
x-cart Gold 4.4.5
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 07:38 AM.

   

 
X-Cart forums © 2001-2020