Jump to content

Validate Email Address on Checkout


Serenade

Recommended Posts

I'm honestly pretty surprised this functionality is not built into WHMCS at this point... That being said, I'm looking for a way to validate the email address on checkout to prevent fake emails on trial signups. I found a piece of code on the internet that supposedly does exactly that, but I need to somehow convert it into an action hook for the checkout.

 

I think it should be a fairly quick and easy job for someone who knows what they're doing, I however do not. Any help is appreciated!

 

function MX_record_check($email) {
   $domain = substr($email, strpos($email,"@")+1);
   return getmxrr($domain,$mxhosts);
}

Link to comment
Share on other sites

if you need to validate email address the validation can be something like that,

 

<?php

function hook_clientValidateEmailAddress($vars){
   if (!filter_var($vars['email'], FILTER_VALIDATE_EMAIL)){
       return array("Invalid Email Address.");
   }
}
add_hook("ClientDetailsValidation", 1, "hook_clientValidateEmailAddress");

?>

Link to comment
Share on other sites

I guess it depends what you mean by "validate" - I would imagine the hook (or any code, so no criticism of sentq!) would consider serenade@whmcs.com as being valid even though the address probably doesn't exist... so valid and fake!

 

if you wanted to do more than just check the syntax of the email address, then you may need to send a verification email to the address - there are at least a couple of addons in the App Store that can do that.

Link to comment
Share on other sites

I guess it depends what you mean by "validate" - I would imagine the hook (or any code, so no criticism of sentq!) would consider serenade@whmcs.com as being valid even though the address probably doesn't exist... so valid and fake!

 

if you wanted to do more than just check the syntax of the email address, then you may need to send a verification email to the address - there are at least a couple of addons in the App Store that can do that.

 

I was under the impression the code I provided in the original post actually checked the MX record using a built in PHP function: http://php.net/manual/en/function.getmxrr.php

 

It doesn't appear to me the hook sentq provided is using that function.

 

If you wanted to do more than just check the syntax of the email address, then you may need to send a verification email to the address - there are at least a couple of addons in the App Store that can do that.

 

There's only one that I found for $30 which seems excessive if it can easily recreate it with a built in PHP function.

Edited by Serenade
Link to comment
Share on other sites

I was under the impression the code I provided in the original post actually checked the MX record using a built in PHP function: http://php.net/manual/en/function.getmxrr.php

did you read the boxed note on the above page?

 

Note: This function should not be used for the purposes of address verification.

 

It doesn't appear to me the hook sentq provided is using that function.

it isn't - it will just check the syntax of the address.

 

There's only one that I found for $30 which seems excessive if you can easily recreate it with a built in PHP function.

except you can't use the function to verify an email address. :)

 

$15 - https://www.whmcs.com/appstore/2998/Email-Verify.html

$16 - https://www.whmcs.com/appstore/3050/Security-Plusplus.html

$20 - https://www.whmcs.com/appstore/1378/HTB-Email-Verification.html

Link to comment
Share on other sites

as brain said what type of validation you need, my code will verify the email address format and it use native PHP function.

 

if you need to validate the existence of email address this will be another story, and you'll need any of the addons available for that purpose

Link to comment
Share on other sites

Would it be possible to use dns_get_record() (with type = MX) instead?

 

2 of the 3 addons you suggested require users to verify their emails by sending verification codes (which is a barrier I have no interest in placing), and the other just checks against a disposable email list. Besides I'm not really looking for a major addon to do something as simple as checking an email.

Link to comment
Share on other sites

2 of the 3 addons you suggested require users to verify their emails by sending verification codes (which is a barrier I have no interest in placing), and the other just checks against a disposable email list. Besides I'm not really looking for a major addon to do something as simple as checking an email.

is it simple? if you just want to check an address is syntax correct, then yes that's simple - sentq's original hook will do that.

 

but there's no guarantee that using mx records will give an accurate answer, e.g yahoo.com always reports addresses as available even if they're not - even on sentq's link above, it states it won't work on all mail servers - one reason for that would be to prevent spammers from simply querying the mail server to find actual email addresses!

 

so at best, the response will be a guess and not definitive.

 

verification codes would be the best way, but if you feel that's a step too far for your needs, then you will have to accept that any verification response you get might be wrong.

Link to comment
Share on other sites

is it simple? if you just want to check an address is syntax correct, then yes that's simple - sentq's original hook will do that.

 

but there's no guarantee that using mx records will give an accurate answer, e.g yahoo.com always reports addresses as available even if they're not - even on sentq's link above, it states it won't work on all mail servers - one reason for that would be to prevent spammers from simply querying the mail server to find actual email addresses!

 

so at best, the response will be a guess and not definitive.

 

verification codes would be the best way, but if you feel that's a step too far for your needs, then you will have to accept that any verification response you get might be wrong.

 

I'm ok with the check not being definitive, it's better than what WHMCS is checking now, which is nothing. Sentq's link looks like it does what I want, but I'm not really sure how to go about making that into a hook.

Link to comment
Share on other sites

Would it be possible to use dns_get_record() (with type = MX) instead?

 

2 of the 3 addons you suggested require users to verify their emails by sending verification codes (which is a barrier I have no interest in placing), and the other just checks against a disposable email list. Besides I'm not really looking for a major addon to do something as simple as checking an email.

 

https://www.whmcs.com/appstore/3050/Security-Plusplus.html

It also validates MX records as an option, as well as blocks disposable and free email accounts.... but sounds like you want someone to write a plugin for free anyway :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated