How To Get Store Email addresses in Magento 2.x / Adobe Commerce by Programmatically

The following below code to get store Email Address

<?php
namespace John\Mage2db\Controller\Index;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class Index extends \Magento\Framework\App\Action\Action
{
    protected $request;
    protected $scopeConfig;

public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\App\Request\Http $request,
    ScopeConfigInterface $scopeConfig
){
    parent::__construct($context);
    $this->scopeConfig = $scopeConfig;
    $this->request = $request;
}

public function execute()
{
    $email = $this->scopeConfig->getValue('trans_email/ident_support/email',ScopeInterface::SCOPE_STORE);
    $name  = $this->scopeConfig->getValue('trans_email/ident_support/name',ScopeInterface::SCOPE_STORE);

    echo $email;echo "<br/>";
    echo $name;echo "<br/>";

}

The abovecode provide Store Support Email ID & Name

If you want to do General Email, Sales Email, Customer Support Email, Customer Support Email1 and Customer Support Email2

General :– ident_general

Sales:- ident_sales

Customer Support:- ident_support

Custom Email1:- ident_custom1

Custom Email2:- ident_custom2

Change below line code as per your business need ident_support to ident_general or ident_sales or ident_custom1 or ident_custom2
$email = $this->scopeConfig->getValue('trans_email/ident_support/email',ScopeInterface::SCOPE_STORE);
    $name  = $this->scopeConfig->getValue('trans_email/ident_support/name',ScopeInterface::SCOPE_STORE);

Leave a Reply

Your email address will not be published. Required fields are marked *