Jump to content

Verification with Signup Email Hook


Recommended Posts

  • WHMCS Developer

In WHMCS Version 6.3 the Email Verification functionality was introduced; if you are not familiar with this feature then you can read more about it at https://docs.whmcs.com/Client_Email_Verification. When this feature is enabled WHMCS will no longer send the "Client Signup Email" template, but will instead deliver the "Client Email Address Verification" template to the client.

 

In this post we are going to be introducing a fairly basic hook that ensures both the "Client Email Address Verification" and "Client Signup Email" templates are delivered to the client upon signup.

 

You can download this hook in a .txt file directly by clicking on the following link: verifywelcomeemail.txt. Once downloaded, you can rename this "verifywelcomeemail.php" and upload it to the "includes/hooks" directory on your server. Alternatively, you can create a new .php file, preferably named something that let you know what the file does at a glance, in the "includes/hooks" directory on your server. Then you can copy the code below, paste it into your new .php file, and save it.

 

<?php

/**
*
* This hook sends out the 'Client Signup Email'
* template when 'Email Verification' is enabled.
*
* @package     WHMCS
* @author      WHMCS Nathan
* @copyright   Copyright (c) WHMCS Limited 2005-2017
* @license     https://www.whmcs.com/license WHMCS Eula
* @link        https://www.whmcs.com/
*
*/

if (!defined('WHMCS')) {
    die('This hook should not be run directly');
}

use WHMCS\Config\Setting;

function sendSignupMail($userId){
   $postData = [];
   $postData = [
       'messagename' => 'Client Signup Email',
       'id' => $userId,
       ];
   $results = localAPI('SendEmail', $postData, 0);
}

add_hook('ClientAdd', 1, function($vars){
   $emailVerificationStatus = Setting::getValue('EnableEmailVerification');

   if($emailVerificationStatus){
       sendSignupMail($vars['userid']);
   }
});

 

This hook relies on a couple elements to function; first it is executed when the ClientAdd hook is run. This hook executes any time a client is being added to WHMCS. An in depth read-out of this hook can be located at https://developers.whmcs.com/hooks-reference/client/#clientadd.

 

Once the hook is run it then uses the Setting::getValue class and method to check whether or not Email Verification is enabled on the installation. Detailed information about this class, and its methods, can be found at https://docs.whmcs.com/classes/7.1/WHMCS/Config/Setting.html.

 

Once it has verified that Email Verification is enabled on the installation, it then uses the localAPI to send a SendEmail command to WHMCS. This command is used to send out the "Client Signup Email" tenmplate itself. Information about the SendEmail command can be found at https://developers.whmcs.com/api-reference/sendemail/.

 

Those two components are all that this hook is really made from, and as such there is not much that can go wrong. With that said, at the time of this writing, this hook was tested with the current versions of WHMCS that fall under Active Support as listed at https://docs.whmcs.com/Long_Term_Support#Active_Development and is not guaranteed to work with prior versions of WHMCS.

 

If you have any feedback, comments, or questions concerning this hook then please let me know; I would be more than happy to address them!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • 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