-
-
- Submit Updated Articles to Bing and Yandex with IndexNow in Joomla
- Add Published and Modified Date Meta Tags to Joomla
- Add Open Graph and Twitter Card Tags to Joomla
- Auto-Generate Meta Descriptions from Article Text in Joomla
- Add Noindex to Specific Pages in Joomla
- Verify Your Joomla Site with Google Search Console
-
- Add a View as Markdown Link to Joomla Articles
- Display the Last Modified Date in Joomla Articles
- Embed Iframes in Joomla
- Automatically Link Twitter (X) @mentions in Joomla Articles
- Open External Links in a New Tab in Joomla
- Display Estimated Reading Time in Joomla Articles
- Replace Old URLs in Joomla
- Search and Replace in Joomla
-
- Add a Footer Line to the Joomla Administrator
- Show a Staging Banner in the Joomla Administrator
- Remove the "All" Option from Admin List Limits in Joomla
- Add a Cookie Consent Banner to Joomla
- Make the Administrator Navigation Sticky in Joomla
- Add Google Fonts to Joomla
- Add a Facebook Messenger Chat Button to Joomla
- Add a Reading Progress Bar to Joomla
- Add a Custom Scrollbar to Joomla
- Show Confetti on a Thank You Page in Joomla
- Add Smooth Scrolling to Joomla
- Add a Back to Top Button in Joomla
- Add a WhatsApp Chat Button in Joomla
-
- Protect the Administrator with a Secret URL Key in Joomla
- Show a Welcome Message on First Login in Joomla
- Log Out Idle Administrators in Joomla
- Assign New Users to a Different User Group Automatically in Joomla
- Redirect Visitors by Country in Joomla
- Redirect Users After Login by User Group in Joomla
- Block User Registration with Certain Usernames in Joomla
- Block User Registration by Country in Joomla
- Block User Registration by Email Address in Joomla
- Block User Registration by IP Address in Joomla
- Remove the Forgot Password and Username Links in Joomla
- Remove the Generator Meta Tag in Joomla
- Let Users Log In with Their Email Address in Joomla
- Block Traffic by Country in Joomla
- Block Bot Traffic in Joomla
- Block Traffic by IP Address in Joomla
Block User Registration by Email Address in Joomla
Keep disposable and spam email addresses out of your Joomla member list by blocking sign-ups from chosen domains, using one PHP snippet.
Half of your new accounts come from throwaway addresses at mailinator.com or from the same 2 spam domains, and none of those people ever log in. Or the opposite problem: your site is for staff, and sign-ups should only work with a company address. You can block user registration by email address in Joomla with one PHP snippet in Code Snippets.
The PHP snippet code
The snippet runs right before Joomla stores a new account. It compares the email address with your list and, depending on the mode, cancels the registration and shows your message on the form. Logins, profile edits and existing accounts aren't affected.
use Joomla\CMS\Factory;
// Email domains or full addresses. A * matches anything, so '*.ru'
// covers every domain that ends in .ru.
$list = [
'mailinator.com',
'*.ru',
'spammer@example.com',
];
// 'block' rejects addresses that match the list.
// 'allow' accepts only addresses that match, for example your company domain.
$mode = 'block';
// Message shown on the registration form instead of the welcome message.
$message = 'Registration with this email address is not allowed.';
// Do not edit below.
$app = Factory::getApplication();
$app->registerEvent('onUserBeforeSave', function ($event) use ($list, $mode, $message)
{
// Only new accounts. Profile edits pass through.
if (!$event->getArgument('isNew', $event->getArgument(1, false)))
{
return;
}
$data = $event->getArgument('data', $event->getArgument(2, []));
$email = strtolower(trim($data['email'] ?? ''));
$domain = substr(strrchr($email, '@'), 1);
$listed = false;
foreach ($list as $pattern)
{
$pattern = strtolower(trim($pattern));
if ($pattern === '')
{
continue;
}
// Patterns with an @ match the full address, the rest match the domain.
$subject = strpos($pattern, '@') === false ? $domain : $email;
if (fnmatch($pattern, $subject))
{
$listed = true;
break;
}
}
$blocked = $mode === 'allow' ? !$listed : $listed;
if ($blocked)
{
// Joomla cancels the registration and shows this message.
throw new RuntimeException($message);
}
});
Change the 3 settings at the top:
$list: domains or full addresses. A domain likemailinator.commatches every address at that domain. A*matches anything, so*.rucovers every domain that ends in .ru. An entry with an @ matches one full address. The list isn't case sensitive.$mode: keep'block'to reject the addresses on your list. Set it to'allow'to accept only the addresses on your list, for example your company domain, and reject everything else.$message: the text Joomla shows on the registration form. It appears after "Registration failed:".
How to add this snippet
- Install Code Snippets if it isn't installed already.
- Log into your Joomla backend.
- Go to Components → Tassos Code Snippets.
- Click New.
- Enter a title, for example Block registration by email.
- Set Code Type to PHP.
- Set Insertion Method to Auto-Insert Locations.
- Set Location to On Page Load.
- Paste the code above into the editor.
- Replace the sample list with your own domains and addresses.
- Click Save & Close.
Check that it works
- Open your site's registration page in a private browser window.
- Submit the form with an address at a blocked domain, for example
test@mailinator.com.
Joomla shows "Registration failed: Registration with this email address is not allowed." and creates no account. Submit the form again with an address that isn't on the list, and the registration goes through.
To block sign-ups by IP address, country or username, see Block User Registration by IP Address in Joomla, Block User Registration by Country in Joomla and Block User Registration with Certain Usernames in Joomla. To learn more about how PHP snippets work, read the PHP snippet docs.