Skip to content

Instantly share code, notes, and snippets.

Last active February 27, 2023 21:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save RWJMurphy/3ee801306f2cfca79d61b38041dcdaed to your computer and use it in GitHub Desktop.
Save RWJMurphy/3ee801306f2cfca79d61b38041dcdaed to your computer and use it in GitHub Desktop.
WHMScripts: Disabling invoice creation emails in WHMCS on a per-client basis

If you’re using WHMCS to manage your cPanel shared servers, this is probably a request that you’ve received a few times. You have clients that are set up to pay invoices automatically from their credit cards, and they’d rather not receive the “Invoice Created” or “Invoice Payment Reminder” emails every month.

Normally WHMCS only allows you to disable these emails globally but, by making use of the EmailPreSend action hook, we can set up a list of clients not to receive these.

To get started just download the following script, change the file extension to .php, edit it to set up the $client_ids and place it in your WHMCS /includes/hooks/ directory

Please note, this script doesn’t disable only the automatically sent invoice notification emails, but also blocks manual sending of these for the selected clients.

(originally posted at

* disable_invoice_notification.php
* Version 1.0
* An action hook for WHMCS that allows you to disable sending of invoice
* creation notifications for selected clients.
* To install, just set the $client_ids and (optionally) $logfile variables
* then place this script in your whmcs/includes/hooks/ directory.
* Tested with WHMCS 4.5.2
* Reed Murphy <> 2010
* For more free cPanel / WHM / WHMCS scripts, check out
function hook_disable_invoice_notification($vars) {
// If $logfile is not blank, messages about emails not sent will be
// logged to this file.
// $logfile = "/home/whmcs/presendemail.log";
// $logfile = "";
$logfile = "";
// An array of IDs of clients that should not receive invoice notification
// emails. Replace these with your own.
$client_ids = Array(
// The names of the email templates that you don't want sent.
$message_names = Array(
"Credit Card Invoice Created",
"Invoice Created",
"Invoice Payment Reminder"
$merge_fields = array();
if (in_array($vars['messagename'], $message_names)) {
$invoice_id = mysql_real_escape_string($vars['relid']);
$query =
"SELECT `userid`, CONCAT_WS(' ', `firstname`, `lastname`) as 'name' ".
"FROM `tblinvoices` ".
"JOIN `tblclients` ON `tblinvoices`.`userid` = `tblclients`.`id` ".
"WHERE `tblinvoices`.`id` = '" . $invoice_id ."'";
$r = full_query($query);
if ($r) {
$row = mysql_fetch_row($r);
$client_id = $row[0];
$client_name = $row[1];
if (in_array($client_id, $client_ids)) {
$merge_fields['abortsend'] = true; // don't send email
if ($logfile) {
$pid = getmypid();
$logline = sprintf(
"%s pre_send_email[%d]: ".
"Not sending email '%s' to client %s\n",
date("Y-m-d H:i:s"),
$fh = fopen($logfile, "a");
fwrite($fh, $logline);
return $merge_fields;
add_hook("EmailPreSend", 10, "hook_disable_invoice_notification");
Copy link

This is a cool gist. I've been researching the issue because we have a payment method, "Debit Order/Direct Debit" which my never send invoice reminder. I'll adopt your gist to accommodate it and publish it here.

My other reseaerch on this issue:

A simple version of your gist:

A feature request asking for almost exactly what I need:

Copy link

Works like a charm. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment