loading...

Send email in magento 2.3 and beyond

mrtuvn profile image Tu Nguyen ・1 min read

First you need inject class TransportBuilder default to your constructor

\Magento\Framework\Mail\Template\TransportBuilder


            $this->_transportBuilder->setTemplateIdentifier(
                $this->_scopeConfig->getValue(
                    self::XML_PATH_ERROR_TEMPLATE,
                    \Magento\Store\Model\ScopeInterface::SCOPE_STORE
                )
            )->setTemplateOptions(
                [
                    'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
                    'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
                ]
            )->setTemplateVars(
                ['warnings' => join("\n", $importWarnings)]
            )->setFrom(
                $this->_scopeConfig->getValue(
                    self::XML_PATH_ERROR_IDENTITY,
                    \Magento\Store\Model\ScopeInterface::SCOPE_STORE
                )
            )->addTo($errorRecipient);
            $transport = $this->_transportBuilder->getTransport();
            $transport->sendMessage();

Discussion

pic
Editor guide