0

Once the customer has been successfully registered, the extension should invoke the following actions.

  • Send an email with the customer data (customer first name, customer last name, customer email) to the Customer Support email address configured in Magento

Thanks so much!!!

0

2 Answers 2

1

Reference link

You can send notification with the use of observer. You need to have email template id , sender information and receiver information.

Please follow below steps.

Step 1: Please create events.xml file under path PackageName/Vendor/etc/

<?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_login">
        <observer name="customer_login_observer" instance="PackageName\Vendor\Observer\CustomerLogin" />
    </event>
</config>

Step 2: Please create CustomerLogin.php file under path PackageName/Vendor/Observer/

<?php
namespace PackageName\Vendor\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Area;

class CustomerLogin implements ObserverInterface
{
    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $_storeManager;

    /**
     * @var \Magento\Framework\Mail\Template\TransportBuilder
     */
    private $transportBuilder;

    /**
     * @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     */
    public function __construct(
        \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
        \Magento\Store\Model\StoreManagerInterface $storeManager
    ) {
        $this->transportBuilder = $transportBuilder;
        $this->_storeManager = $storeManager;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $customer = $observer->getEvent()->getCustomer();
        $this->sendEmail($customer);
    }

    public function sendEmail($customer)
    {
        $senderInfo = [
            'name' => $customer->getName(),
            'email' => $customer->getEmail(),
        ];

        $recieverEmail = 'test@zealousweb.com';
        $emailTemplateId = 2;// Here change template id or if you have configuration for email template then pass here

        $emailTemplateVariables = [];
        $emailTempVariables['name'] = $customer->getName();

        $postObject = new \Magento\Framework\DataObject();
        $postObject->setData($emailTempVariables);
        
        $transport = $this->transportBuilder->setTemplateIdentifier($emailTemplateId)
                    ->setTemplateOptions(
                        [
                            'area' => Area::AREA_FRONTEND,
                            'store' => $this->_storeManager->getStore()->getId()
                        ]
                    )
                    ->setTemplateVars(['data' => $postObject])
                    ->setFrom($senderInfo)
                    ->addTo($recieverEmail)
                    ->setReplyTo($recieverEmail)
                    ->getTransport();
        $transport->sendMessage();
    }
}

I have created email template from admin and passed that email template id. Please change and set email template as per your need.

Email Template Content:- https://prnt.sc/10gzmza

{{template config_path="design/email/header_template"}}

<p class="greeting">Dear {{var data.name}},</p>

Please set content according to your need.

{{template config_path="design/email/footer_template"}}
3
  • why i did it your way, when creating an account and login nothing happens, can you help me more!!!
    – Nam Cong
    Dec 15, 2022 at 9:12
  • you follow all the step ? Dec 15, 2022 at 12:30
  • Thanks and Best regards,
    – Nam Cong
    Dec 15, 2022 at 14:38
0

Use plugin intends of observer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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