This script adds a clean, admin-facing form that creates a WHMCS client via API, optionally:
- 
activates them as an affiliate,
 - 
sends the welcome email,
 - 
opens a support ticket with the client’s website URL + notes,
 - 
logs consent to admin notes and/or ticket,
 - 
uses Country/State/Language dropdowns sourced from your WHMCS install,
 - 
enforces password policy with live hints + confirmation,
 - 
lets admins customize a success message (and optional redirect).
 
All admin behaviors are controlled in config.php (not exposed on the form).
Requirements
- 
WHMCS: v8.x (works with v7.10+ in most cases).
 - 
PHP: 7.4 – 8.x with
curlandopensslextensions. - 
Web server: HTTPS recommended (TLS verification on).
 - 
WHMCS API access with the following Allowed API Actions:
- 
AddClient - 
UpdateClient - 
AffiliateActivate(if affiliate activation enabled) - 
OpenTicket(if ticket creation enabled) 
 - 
 
Tip: Use a dedicated “API User” with a limited API Role that includes only the actions above.
File Structure
Ship your ZIP with a simple, predictable layout:
- 
whmcs-add-client.php: The form + handler file (drop-in). - 
config.php: All settings: API creds, toggles, messaging, paths, etc. - 
Documentation: This guide in HTML/MD.
 - 
Changelog: Versioned changes for marketplaces.
 - 
License: Your license text.
 
Marketplace best practice: publish
config.sample.phpin/upload/, and tell users to copy it toconfig.phpso they don’t accidentally overwrite configs during updates.
Step-by-Step Installation
1) Upload files
- 
Unzip your package locally.
 - 
Upload everything inside
/upload/to a secure directory on your server (e.g./var/www/thexyz/account/add-client/or/public_html/whmcs-tools/add-client/). - 
Ensure
whmcs-add-client.phpandconfig.phpare in the same directory. 
If you put
config.phpelsewhere, update therequire_oncepath inwhmcs-add-client.php.
2) Prepare WHMCS API credentials
In WHMCS Admin:
- 
System Settings → Staff Management → API Credentials (older versions: Setup → Staff Management → API Credentials).
 - 
Create a new API Credential (identifier/secret) for a service account user.
 - 
Assign an API Role that includes the required actions (see Requirements).
 - 
If your
configuration.phpuses an API Access Key, copy that value intoconfig.php$api_access_key. 
3) Configure config.php
- 
Open
config.phpand set: 
API
Admin controls (no UI)
Ticket
Consent + Links
WHMCS filesystem paths for dropdowns
Password policy
Success message + optional redirect
Website URL behavior
4) Find your Support Department ID
- 
WHMCS Admin → Support → Support Departments.
 - 
Open a department; the ID is visible in the URL (e.g.,
id=1). - 
Put that ID into
$TICKET_DEPT_ID. 
5) Open the form
Navigate to the URL where you uploaded whmcs-add-client.php (e.g. https://yourdomain.com/whmcs-tools/add-client/whmcs-add-client.php).
Security Best Practices
- 
Do not hard-code API credentials. Use environment variables or a protected
config.php. - 
Place
config.phpoutside web root if possible, or deny public access with.htaccess: - 
Keep
$api_verify_peer = true(default) to validate TLS. - 
Serve the page via HTTPS only.
 - 
Consider adding a CSRF token if the page is publicly reachable (simple session token).
 - 
Restrict access (e.g., protect the directory with HTTP auth or IP allowlist) if this is internal-only tooling.
 
Testing Checklist
- 
API connectivity
- 
Intentionally break the identifier/secret to ensure you see a helpful error.
 
 - 
 - 
Client creation
- 
Submit the form with test data. Confirm the new client appears in WHMCS.
 
 - 
 - 
Welcome email
- 
Toggle
$SEND_WELCOME_EMAILand watch whether an email is sent (check Email Log). 
 - 
 - 
Status & Group
- 
Set
$CLIENT_STATUStoInactiveorClosed; verify client status afterwards. - 
Set
$CLIENT_GROUP_IDto a real group ID; verify assignment. 
 - 
 - 
Affiliate
- 
Enable
$ACTIVATE_AS_AFFILIATE = true; confirm the affiliate profile is created. 
 - 
 - 
Ticket
- 
Enable
$CREATE_TICKET = true; verify a ticket opens in the correct department with website URL + notes. 
 - 
 - 
Consent logging
- 
Enable
$OPTIN_ENABLEand check that consent is written to admin notes and/or ticket when checked. 
 - 
 - 
Country/State/Language dropdowns
- 
Change country to US/CA and confirm a state select appears; pick a language from
/lang. 
 - 
 - 
Password policy
- 
Verify real-time hints and server-side enforcement; confirm mismatch detection.
 
 - 
 - 
Success message & redirect
- 
Customize
$SUCCESS_MESSAGE_TEMPLATE; optionally enable$SUCCESS_REDIRECT_URLand test. 
 - 
 
Troubleshooting
Blank Country/Language dropdowns
- 
Double-check
$WHMCS_ROOTpath. - 
Ensure the following files/directories exist and are readable by PHP:
- 
{$WHMCS_ROOT}/resources/country/dist.countries.json - 
{$WHMCS_ROOT}/lang/ 
 - 
 
“AddClient failed”
- 
Confirm API Role has
AddClientpermission. - 
Check Response: your script echoes a human-readable message; enable display_errors in dev.
 
Ticket not created
- 
Set
$CREATE_TICKET = trueand a valid$TICKET_DEPT_ID. - 
API Role must include
OpenTicket. 
Affiliate not activated
- 
Ensure
AffiliateActivatepermission is granted. 
TLS/SSL error
- 
Make sure the site has a valid certificate; keep
$api_verify_peer = true. 
Permissions error
- 
In WHMCS Admin → API Roles, confirm your API user’s role includes all required actions.
 
Marketplace Packaging (WHMCS Marketplace, Codester, CodeCanyon)
What to include in the ZIP
- 
/upload/folder withwhmcs-add-client.php+config.sample.php(notconfig.phpto avoid accidental credential leaks). - 
/documentation/index.html(this guide, nicely styled). - 
/changelog/CHANGELOG.md(semantic versioning recommended:1.0.0,1.1.0, etc.). - 
/license/LICENSE.txt. - 
Optional
/screenshots/for your product page. 
Product Page Essentials
- 
Title: “Add Client to WHMCS (Affiliate + Ticket + Consent)”
 - 
Short description: 1–2 sentences of value.
 - 
Feature bullets:
- 
Create clients via API with password policy + double confirm
 - 
Optional welcome email, affiliate activation, support ticket
 - 
Admin-only toggles in
config.php(no UI exposure) - 
Country/State/Language dropdowns from your WHMCS
 - 
Custom success message + optional redirect
 - 
Consent logging (TCPA/CASL/GDPR-friendly)
 
 - 
 - 
Requirements: WHMCS 8.x, PHP 7.4–8.2, cURL.
 - 
Changelog: Paste from
CHANGELOG.md. - 
Support policy: Response times, supported PHP/WHMCS versions, how to contact.
 - 
Demo (optional but recommended): host a sanitized demo page; stub out API calls or use a staging WHMCS.
 
Envato (CodeCanyon) Notes
- 
Provide good documentation (HTML) and clear versioning.
 - 
No encoded/obfuscated code for simple tools; if you encrypt, declare it and provide requirements (e.g., ionCube).
 
Codester Notes
- 
Add multiple screenshots; keep description technical but concise.
 - 
Include an install video/GIF if possible.
 
WHMCS Marketplace Notes
- 
Ensure compliant with the WHMCS EULA and branding guidelines.
 - 
Provide compatibility info by WHMCS major versions.
 - 
Consider packaging as an “Integration” rather than an addon module (this is a standalone script).
 
Updating / Upgrading
- 
Never overwrite a live
config.php. Useconfig.sample.phpas the template and diff changes. - 
Maintain a CHANGELOG.md with dates and highlights.
 - 
Bump semantic versions (e.g.,
1.1.0) when changing config options or adding features. 
Optional Hardening (for public-facing installs)
- 
CSRF protection: add a session token to the form and validate on POST.
 - 
reCAPTCHA: protect from spam if the page is not behind auth.
 - 
Auth guard: wrap the page with simple HTTP auth or an IP allowlist.
 
Uninstall
- 
Delete the uploaded directory and any
.htaccessprotectingconfig.php. - 
API user/role can remain for other integrations or be removed from WHMCS.