adinase Posted April 27, 2021 Share Posted April 27, 2021 We are trying to prevent all emails from being sent from whmcs for customers under " old customer " group The below one fails to prevent emails, failing to figure this out !! Can anyone help?? ... where are getting it wrong ?? <?php use WHMCS\Database\Capsule; add_hook('EmailPreSend', 1, function($vars) { $disallowedGroupID = '1'; // Insert Client Group ID $emailTemplates = array('Credit Card Payment Due', 'Automated Password Reset', 'Invoice Created', 'Invoice Modified', 'Upgrade Order Cancelled', 'Other Product/Service Welcome Email', 'Cancellation Request Confirmation', 'First Invoice Overdue Notice', 'Password Reset Validation', 'Invoice Payment Reminder', 'Second Invoice Overdue Notice', 'Third Invoice Overdue Notice', 'Domain Registration Confirmation', 'Domain Renewal Confirmation', 'Domain Transfer Completed', 'Domain Transfer Failed', 'Domain Transfer Initiated', 'Expired Domain Notice', 'Upcoming Domain Renewal Notice', 'Order Confirmation', 'Password Reset Confirmation', 'Client Signup Email', 'Client Email Address Verification', 'Default Notification Message', 'Hosting Account Welcome Email', 'Service Suspension Notification', 'Service Unsuspension Notification', 'Support Ticket Opened', 'Support Ticket Reply', 'Support Ticket Auto Close Notification''Credit Card Invoice Created', 'Credit Card Payment Confirmation', 'Credit Card Payment Failed', 'Credit Card Payment Pending', 'Direct Debit Payment Confirmation', 'Direct Debit Payment Failed', 'Direct Debit Payment Pending', 'Direct Debit Payment Failed', 'Credit Card Invoice Created', 'Credit Card Payment Confirmation', 'Credit Card Payment Failed', 'Credit Card Payment Pending', 'Direct Debit Payment Confirmation', 'Direct Debit Payment Failed', 'Direct Debit Payment Pending', 'Direct Debit Payment Failed'); // Email Templates to block if (in_array($vars['messagename'], $emailTemplates)) { if (!Capsule::select(Capsule::raw('SELECT id FROM tblclients WHERE id = "' . $vars['relid'] . '" AND groupid = "' . $groupid . '" LIMIT 1'))) { $output['abortsend'] = true; return $output; } } }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 28, 2021 Share Posted April 28, 2021 On 27/04/2021 at 09:50, adinase said: We are trying to prevent all emails from being sent from whmcs for customers under " old customer " group EmailPreSend would only prevent most templated emails from being sent. On 27/04/2021 at 09:50, adinase said: The below one fails to prevent emails, failing to figure this out !! I take it that you're working off Kian's hook code... https://github.com/Katamaze/WHMCS-Action-Hook-Factory/blob/master/hooks/PreventEmailSendingBasedOnClientGroup.php On 27/04/2021 at 09:50, adinase said: Can anyone help?? ... where are getting it wrong ?? two obvious issues - there may be others. the relid value will be different I think depending on what email type the message is (e.g general, product, invoice, support etc) - the point being that it won't always be a client ID value.... depending on the type, you might need to use a database query to get the client ID value by using relid as a starting point. the query references a $groupid variable, but that variable is never defined in the hook. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted April 28, 2021 Share Posted April 28, 2021 As stated here... $emailTemplates = array('... cut..'); // Email Templates to block (General Messages) ... by default the hook in question works only with General Messages. If you want to prevent other types of emails, you'll need to change the query accordingly. You can use as reference sendEmail API. I quote: Quote What you must provide for the Related ID depends upon the type of email being sent. The available options are: General Email Type = Client ID (tblclients.id) Product Email Type = Service ID (tblhosting.id) Domain Email Type = Domain ID (tbldomains.id) Invoice Email Type = Invoice ID (tblinvoices.id) Support Email Type = Ticket ID (tbltickets.id) Affiliate Email Type = Affiliate ID (tblaffiliates.id) 0 Quote Link to comment Share on other sites More sharing options...
adinase Posted June 7, 2021 Author Share Posted June 7, 2021 Any specific way to block all emails for GroupID = '1' 0 Quote Link to comment Share on other sites More sharing options...
adinase Posted June 7, 2021 Author Share Posted June 7, 2021 This one below is working now !! <?php use WHMCS\Database\Capsule; function hook_disableAllEmails($vars) { $disallowedGroupID = '1'; // Insert Client Group ID $emailTemplates = array('Credit Card Payment Due', 'Automated Password Reset', 'Invoice Created', 'Invoice Modified', 'Upgrade Order Cancelled', 'Other Product/Service Welcome Email', 'Cancellation Request Confirmation', 'First Invoice Overdue Notice', 'Password Reset Validation', 'Invoice Payment Reminder', 'Second Invoice Overdue Notice', 'Third Invoice Overdue Notice', 'Domain Registration Confirmation', 'Domain Renewal Confirmation', 'Domain Transfer Completed', 'Domain Transfer Failed', 'Domain Transfer Initiated', 'Expired Domain Notice', 'Upcoming Domain Renewal Notice', 'Order Confirmation', 'Password Reset Confirmation', 'Client Signup Email', 'Client Email Address Verification', 'Default Notification Message', 'Hosting Account Welcome Email', 'Service Suspension Notification', 'Service Unsuspension Notification', 'Support Ticket Opened', 'Support Ticket Reply', 'Support Ticket Auto Close Notification','Credit Card Invoice Created', 'Credit Card Payment Confirmation', 'Credit Card Payment Failed', 'Credit Card Payment Pending', 'Direct Debit Payment Confirmation', 'Direct Debit Payment Failed', 'Direct Debit Payment Pending', 'Direct Debit Payment Failed', 'Credit Card Invoice Created', 'Credit Card Payment Confirmation', 'Credit Card Payment Failed', 'Credit Card Payment Pending', 'Direct Debit Payment Confirmation', 'Direct Debit Payment Failed', 'Direct Debit Payment Pending', 'Direct Debit Payment Failed'); // Email Templates to block if (in_array($vars['messagename'], $emailTemplates)) { if (!Capsule::select(Capsule::raw('SELECT id FROM tblclients WHERE id = "' . $vars['relid'] . '" AND groupid = "' . $groupid . '" LIMIT 1'))) { $output['abortsend'] = true; return $output; } } } add_hook("EmailPreSend", 1, "hook_disableAllEmails"); ?> Question is how to prevent all emails without defining each and every email in the array ?? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 11, 2021 Share Posted June 11, 2021 On 07/06/2021 at 13:06, adinase said: Question is how to prevent all emails without defining each and every email in the array ?? to prevent all *templated* emails, then you would just remove the in_array as it's that that is limiting which templates the hook applies to. <?php use WHMCS\Database\Capsule; function hook_disableAllEmails($vars) { $disallowedGroupID = '1'; // Insert Client Group ID if (!Capsule::select(Capsule::raw('SELECT id FROM tblclients WHERE id = "' . $vars['relid'] . '" AND groupid = "' . $groupid . '" LIMIT 1'))) { $output['abortsend'] = true; return $output; } } add_hook("EmailPreSend", 1, "hook_disableAllEmails"); 0 Quote Link to comment Share on other sites More sharing options...
adinase Posted June 11, 2021 Author Share Posted June 11, 2021 Thank you king !! ...worked like a charm !! 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.