When managing multiple cPanel accounts, you may need to update the notification email address for all users at once — for example, when switching support email addresses or consolidating contact information.
Manually changing each account’s email from WHM can be time-consuming, but with a simple Bash script, you can automate the process.
Below is a step-by-step guide on how to do it.
1. Prerequisites
Before you begin, make sure you have:
-
Root SSH access to the server.
-
Basic knowledge of running commands in Linux.
-
A backup of your server or at least the
/var/cpanel/users/
directory. (Not compulsory – Recommended)
2. How to Use the Script:
-
Log in to your server via SSH as root:
-
Create a new script file:
-
Paste the script below into the file.
Here’s the cleaned and safe-to-use version of the script:
-
Replace:
-
old@example.com
with your current contact email. -
new@example.com
with your new contact email.
-
-
Save and exit (
CTRL + O
,Enter
, thenCTRL + X
).
6. Make the script executable:
3. How It Works
-
The script checks every cPanel account’s configuration file in
/var/cpanel/users/
. -
It looks for the
CONTACTEMAIL
entry. -
If the entry matches the old email address, it uses WHM’s
modifyacct
API to update it. -
It logs each update result to the terminal.
4 . Important Notes
-
This will only update accounts that have the old email exactly matching what you define in
OLD_EMAIL
. -
If some accounts use different old emails, you’ll need to adapt the script.
-
Always test the script on a staging server or with a small subset of accounts before running it on production.
💡 Pro Tip:
If you want to change all cPanel accounts to the new email regardless of what the old email is, you can modify the script to skip the check for OLD_EMAIL
.
This “universal update” method is faster when you need to replace every account’s contact email in one go.