In my Magento 2 site, I am looking for a way to restrict signing up a user account with all email domains(eg Gmail,Hotmail) except for 2 email domains.

I found a guide that said to go to


to add in new fields in Customer Configuration(Stores -> Configuration -> Customers -> Customer Configuration) that will allow me to configure email domains that I can block.

However, editing the system.xml file does not change anything in Customer Configuration, I have tested this by deleting the entire "Create New Account Options", and have refreshed the Magento Cache.

I am running Magento 2.1.7.

Please advice on what I have done incorrectly. I appreciate your help.


2 Answers 2


This simple extension should helps you to manage customer restriction. https://github.com/magekey/module-customer-restriction

  • I'm sorry, after following the instructions in the link, the extension don't seem to have been installed. Running the composer command works, but running setup:upgrade don't lists out the customer restriction module. Continuing the steps, the extension doesn't appear in stores -> Customer either. It also doesn't show up on my lists of installed extensions. Please advice. Thank you Jun 23, 2017 at 7:13
  • you need move to magento root directory and run composer require magekey/module-customer-restriction Jun 23, 2017 at 7:14
  • after composer work done you need to follow deployment instruction. Jun 23, 2017 at 7:16
  • first make sure you have installed module, check composer.json, you should see line magekey/module-customer-restriction, and of course should be new directory in vendor folder. Jun 23, 2017 at 7:19
  • of course best way use composer, but you always can move module to app/code folder. So if you have any issues with composer just create app/code/MageKey/CustomerRestriction and move all files under this directory. don't forget to deploy it. Jun 23, 2017 at 7:21


<type name="Magento\Customer\Controller\Account\CreatePost">
    <plugin name="restrictCustomerEmail"


 namespace Company\Module\Model\Plugin\Controller\Account;

use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\UrlFactory;
use Magento\Framework\Message\ManagerInterface;

class RestrictCustomerEmail

/** @var \Magento\Framework\UrlInterface */
protected $urlModel;

 * @var \Magento\Framework\Controller\Result\RedirectFactory
protected $resultRedirectFactory;

 * @var \Magento\Framework\Message\ManagerInterface
protected $messageManager;

 * RestrictCustomerEmail constructor.
 * @param UrlFactory $urlFactory
 * @param RedirectFactory $redirectFactory
 * @param ManagerInterface $messageManager
public function __construct(
    UrlFactory $urlFactory,
    RedirectFactory $redirectFactory,
    ManagerInterface $messageManager

    $this->urlModel = $urlFactory->create();
    $this->resultRedirectFactory = $redirectFactory;
    $this->messageManager = $messageManager;

 * @param \Magento\Customer\Controller\Account\CreatePost $subject
 * @param \Closure $proceed
 * @return mixed
 * @throws \Magento\Framework\Exception\LocalizedException
public function aroundExecute(
    \Magento\Customer\Controller\Account\CreatePost $subject,
    \Closure $proceed
    /** @var \Magento\Framework\App\RequestInterface $request */
    $email = $subject->getRequest()->getParam('email');
    list($nick, $domain) = explode('@', $email, 2);
    if (in_array($domain, ['163.com', 'mail.ru'], true)) {

            'Registration is disabled for you domain'
        $defaultUrl = $this->urlModel->getUrl('*/*/create', ['_secure' => true]);
        /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();

        return $resultRedirect->setUrl($defaultUrl);

    return $proceed();

You can check this post out it may help you. It also contains the answer. for reference.

Magento 2: Restrict customer registration by specific mail extension

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Jun 22, 2017 at 10:38
  • @FabianSchmengler Sure will take care of that thanks. Jun 22, 2017 at 11:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.