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
1 2 3 4 5 6 |
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magemonkey_MailtoAdmin', __DIR__ ); |
Step 2: Create event file like
1 2 3 4 5 6 |
<?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="Magemonkey\MailtoAdmin\Observer\MailtoAdmin"/> </event> </config> |
Step 3: Create module file like Magemonkey/MailtoAdmin/etc/module.xml
1 2 3 4 |
<?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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
<?php namespace Magemonkey\MailtoAdmin\Custom\Observer; use Magento\Framework\Event\ObserverInterface; 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( \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Escaper $escaper ) { $this->_transportBuilder = $transportBuilder; $this->inlineTranslation = $inlineTranslation; $this->scopeConfig = $scopeConfig; $this->storeManager = $storeManager; $this->_escaper = $escaper; } public function execute(\Magento\Framework\Event\Observer $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 \Magento\Framework\DataObject(); $postObject->setData($sender); $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; $transport = $this->_transportBuilder ->setTemplateIdentifier('1') ->setTemplateOptions( ['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::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) { \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->debug($e->getMessage()); } } } |
Step 5: Then after run the below commands.
1 2 3 |
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.
[crayon-63d9715a56207058470344/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.