Jump to content

clientID for a send email hook?

Go to solution Solved by leemahoney3,

Recommended Posts

Im trying to create a simple hook to send out an email when an Affiliate account is activated



use WHMCS\Database\Capsule;

add_hook('AffiliateActivation', 1, function($vars) {
    $affiliateId = $vars['affiliateid']; // Retrieve the affiliate ID from the hook's parameters

    // Fetch the client ID associated with the affiliate
    $clientId = Capsule::table('tblaffiliates')
                    ->where('id', $affiliateId)
                    ->value('clientid'); // Directly getting the client ID

    // Check if a valid client ID was retrieved
    if ($clientId) {
        // Send email using the WHMCS email template
        $response = localAPI('SendEmail', [
            'messagename' => 'Welcome to the Affiliate Program',
            'id' => $clientId

        // Log the response for debugging
        logActivity("Send Email API Response: " . json_encode($response, JSON_PRETTY_PRINT));
    } else {
        // Log an error if the client ID was not found
        logActivity("Error: Client ID not found for affiliate ID " . $affiliateId);

if i hard code the client ID to a client that im activating it for it works but otherwise for some reason this code coes back with the error message:

Send Email API Response: {"result":"error","message":"A related ID is required"}

this is in a log line directly after i get a line saying something like:

Activated Affiliate Account - Affiliate ID: 9 - User ID: 30

what am i missing?

Link to comment
Share on other sites

  • 4 months later...

Join the conversation

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

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