cancel
Showing results for 
Search instead for 
Did you mean: 

How to Send Email to Admin After Customer Registration in Magento 2

Highlighted

How to Send Email to Admin After Customer Registration in Magento 2

Hi, good day to you all!

 

I'm searching for a solution for some time now how to fix this:

it's magento 2.2.2 and the store is B2B, so the prices are not visible unless you register and we accept you as wholesaler, change it in the backend of magento so the customer will be able to see the prices and order.

Here's the problem; I don't know when a customer registered.

Does anyone know and willing to help? I cannot find a way to get informed as admin when a customer registered.

 

Thank you in advance for your timeSmiley Happy

kind regards Mariska

6 REPLIES 6
Highlighted

Re: How to Send Email to Admin After Customer Registration in Magento 2

Hi @RockMariska,

 

By default you won't be able to set the BCC for those emails (isn't like the Orders, Invoices, etc emails).

But you can set those options for Company creation (if you are using Companies on your B2B model).

Take a look at: Stores -> Configuration -> Customers -> Company Configuration

 

Cheers

Highlighted

Re: How to Send Email to Admin After Customer Registration in Magento 2

Thank you very much for your response @Damian Culotta,

 

My store is in magento Open Source 2.2.2 I guess what you are suggesting is for magento Commerce Am I right? as I cannot see the company configuration option.

 

Thank you

 

Highlighted

Re: How to Send Email to Admin After Customer Registration in Magento 2

Hi @RockMariska,

 

You're right. My bad.

I've saw B2B and I thought you were talking about the Commerce edition.

In that case, the answer is that you won't be able to do that without customize the code through a module. Magento OOTB won't allow you to add a BCC on that transactional email.

Highlighted

Re: How to Send Email to Admin After Customer Registration in Magento 2

Step1

Create events.xml file in \app\code\Namespace_Modulename\etc\frontend\

<?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="Namespace\module_name \Observer\SendMailToAdmin"/>
    </event>
</config>

 

 

 

 

Step2

*******************************************************

 

Create SendMailToAdmin.php file in \app\code\Namespace_Modulename\Observer\. This observer class is used to send mail after customer is registered successfully.

 

<?php
 
namespace Namespace_Modulename\Custom\Observer;

use Magento\Framework\Event\ObserverInterface;
 
class SendMailToAdmin 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:Smiley FrustratedCOPE_STORE;
            $transport =
                $this->_transportBuilder
                ->setTemplateIdentifier('1') // Send the ID of Email template which is created in Admin panel
                ->setTemplateOptions(
                    ['area' => \Magento\Framework\App\Area::AREA_FRONTEND, // using frontend area to get the template file
                    'store' => \Magento\Store\Model\Store:Smiley Very HappyEFAULT_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());
        }
    
    }
 
}

Highlighted

Re: How to Send Email to Admin After Customer Registration in Magento 2

hi ,

How can i send a notification mail to admin when customer submitted the custom form in magento2? Kindly give me the solution for that

Highlighted

Re: How to Send Email to Admin After Customer Registration in Magento 2

Hi @akshayaven9f88,

 

If you are talking about a custom form, why not add that feature to your form?