We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    By default in Magento 2 does not provide the mail functionality to admin when new customers signup. It means no email will be sent to the admin when a customer registers with the front side.

    If you want to get the mail sent to admin when new customer signup happens then do follow below steps:

    Step 1: Create a registration file like

    <?php
    MagentoFrameworkComponentComponentRegistrar::register(
        MagentoFrameworkComponentComponentRegistrar::MODULE,
        'Magemonkey_MailtoAdmin',
        __DIR__
    );

     

    Step 2: Create event file like

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
        <event name="customer_register_success">
            <observer name="sendmail_toadmin" instance="MagemonkeyMailtoAdminObserverMailtoAdmin"/>
        </event>
    </config>

     

    Step 3: Create module file like Magemonkey/MailtoAdmin/etc/module.xml

    <?xml version="1.0" ?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Magemonkey_MailtoAdmin" setup_version="1.0.0"/>
    </config>

     

    Step 4: Create PHP file in Magemonkey/MailtoAdmin/Observer/MailtoAdmin.php

    <?php
     
    namespace MagemonkeyMailtoAdminCustomObserver;
    
    use MagentoFrameworkEventObserverInterface;
     
    class MailtoAdmin implements ObserverInterface
    {
     
        const XML_PATH_EMAIL_RECIPIENT = 'trans_email/ident_general/email';
        protected $_transportBuilder;
        protected $inlineTranslation;
        protected $scopeConfig;
        protected $storeManager;
         protected $_escaper;
        
        public function __construct(
            MagentoFrameworkMailTemplateTransportBuilder $transportBuilder,
            MagentoFrameworkTranslateInlineStateInterface $inlineTranslation,
            MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
            MagentoStoreModelStoreManagerInterface $storeManager,
            MagentoFrameworkEscaper $escaper
        ) {
            $this->_transportBuilder = $transportBuilder;
            $this->inlineTranslation = $inlineTranslation;
            $this->scopeConfig = $scopeConfig;
            $this->storeManager = $storeManager;
            $this->_escaper = $escaper;
        }
     
        public function execute(MagentoFrameworkEventObserver $observer)
        {
            
            
            $customer = $observer->getData('customer');
            
            $this->inlineTranslation->suspend();
            try
            {
                $error = false;
                
                $sender = [
                    'name' => $this->_escaper->escapeHtml($customer->getFirstName()),
                    'email' => $this->_escaper->escapeHtml($customer->getEmail()),
                ];
                $postObject = new MagentoFrameworkDataObject();
                $postObject->setData($sender);
                $storeScope = MagentoStoreModelScopeInterface::SCOPE_STORE;
                $transport =
                    $this->_transportBuilder
                    ->setTemplateIdentifier('1')
                    ->setTemplateOptions(
                        ['area' => MagentoFrameworkAppArea::AREA_FRONTEND, 
                        'store' => MagentoStoreModelStore::DEFAULT_STORE_ID,]
                    )
                    ->setTemplateVars(['data' => $postObject])
                    ->setFrom($sender)
                    ->addTo($this->scopeConfig->getValue(self::XML_PATH_EMAIL_RECIPIENT, $storeScope))
                    ->getTransport();
                $transport->sendMessage(); ;
                $this->inlineTranslation->resume();
                
                
            }
            catch (Exception $e)
            {
                MagentoFrameworkAppObjectManager::getInstance()->get('PsrLogLoggerInterface')->debug($e->getMessage());
            }
        
        }
     
    }

     

    Step 5: Then after run the below commands.

    php bin/magento setup:upgrade
    php bin/magento setup:static-content:deploy
    php bin/magento cache:flush

     

    That’s it…

    Now clean the cache and check it by creating new customer signup. You will find the mail of new customer’s sign up.

    field_5bfb909c5ccae

      Get a Free Quote