1

This question already has an answer here:

How to get the store email in my custom module in the controller file?

marked as duplicate by Manashvi Birla, Jai, Shoaib Munir, Aasim Goriya, Mohit Kumar Arora Sep 9 at 10:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You can easily get store Email address in controller

<?php
namespace Custom\Module\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);

    echo "Email = ".$email;

$this->_view->loadLayout();
$this->_view->renderLayout();
}

}
1

Please try this code:

protected $scopeConfig;

public function __construct(
        .......
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig        
    ) {
        ...
        $this->_scopeConfig = $scopeConfig;
    }

public function getStoreEmail()
    {
        return $this->_scopeConfig->getValue(
            'trans_email/ident_sales/email',
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }

public function execute()
{
  echo $this->getStoreEmail();
}

Hope It will help you!

0

You have to create first block and defined function inside block for getting store name and store email, inside construct method pass ScopeConfigInterface object

Create the method getStoreName(), getStoreEmail()

    protected $scopeConfig;
    public function __construct(
        .......
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig        
    ) {
        ...
        $this->_scopeConfig = $scopeConfig;
    }

    public function getStorename()
    {
        return $this->_scopeConfig->getValue(
            'trans_email/ident_sales/name',
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }

 public function getStoreEmail()
    {
        return $this->_scopeConfig->getValue(
            'trans_email/ident_sales/email',
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }

Call function inside your template file, like echo $block->getStoreEmail() and echo $block->getStoreName();

  • I don't need email in the template file but i need in a controller class. – AKM Sep 9 at 6:42
  • please explain briefly – Rk Rathod Sep 9 at 6:44
  • I need the Store Owner email address in my controller file. – AKM Sep 9 at 6:47
  • $storeEmail = $this->_scopeConfig->getValue( 'trans_email/ident_sales/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); – Rk Rathod Sep 9 at 6:50
0

You can get from this code.

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,
    ScopeConfigInterface $scopeConfig
){
    parent::__construct($context);
    $this->scopeConfig = $scopeConfig;
}

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


    $this->_view->loadLayout();
    $this->_view->renderLayout();
}
0

Please add below code in your controller.

protected $scopeConfig;
        public function __construct(
            .......
            \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig        
        ) {
            ...
            $this->_scopeConfig = $scopeConfig;
        }
    public function execute()
    {
        $storeemail =  $this->_scopeConfig->getValue(
                'trans_email/ident_sales/email',
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE
            );
        echo $storeemail;
     }

after put in command line with php bin/magento setup:upgrade command

It's working from my side please try with your side...

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