X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Email Validation with TowerData (https://forum.x-cart.com/showthread.php?t=54477)

exsecror 07-05-2010 11:26 AM

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.

Nadeem 07-05-2010 01:51 PM

Re: Email Validation with TowerData
 
Thanks ! very nice

Jeremy Smith 10-21-2010 05:50 AM

Re: Email Validation with TowerData
 
Does this work with v4.1.11?

buywink 02-20-2015 12:44 AM

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

totaltec 02-22-2015 06:26 AM

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.

buywink 02-23-2015 08:27 PM

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.


All times are GMT -8. The time now is 01:08 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.