theozsnowman Posted December 27, 2023 Share Posted December 27, 2023 Im trying to create a simple hook to send out an email when an Affiliate account is activated <?php 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? 0 Quote Link to comment Share on other sites More sharing options...
Solution leemahoney3 Posted December 30, 2023 Solution Share Posted December 30, 2023 Just use the userid variable. $clientId = $vars['userid']; 3 Quote Link to comment Share on other sites More sharing options...
theozsnowman Posted January 3 Author Share Posted January 3 On 12/31/2023 at 4:33 AM, leemahoney3 said: Just use the userid variable. $clientId = $vars['userid']; cheers.. so simple... 0 Quote Link to comment Share on other sites More sharing options...
CMS911 Posted May 13 Share Posted May 13 Can you share your email template? How did you get it to show them their affiliate link? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.