0

I have a special form that when filled needs to send a notification mail to the admin. I used a system.xml to have it selected and stored in the database :

    <field id="identity" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
        <label>Sender</label>
        <source_model>Magento\Config\Model\Config\Source\Email\Identity</source_model>
    </field>

Then I can retrieve it like that :

    $this->scopeConfig->getValue(
            'mysection/mygroup/identity',
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        )

And I get e.g. the string "Sales" that correspond to the entry in vendor/magento/module-email/etc/config.xml :

    <trans_email>
        ...
        <ident_sales>
            <email>[email protected]</email>
            <name>Sales</name>
        </ident_sales>
        ...
    </trans_email>

Is there a way to easily retrieve the email corresponding to the name ?

In the example, I told "Sales" but it can be changed as there is a dropdown so I need to be able to map the name to the email rather that hardcode the sales email address.

1 Answer 1

1
...
use Magento\Framework\Mail\Template\SenderResolverInterface $senderResolver
...

$identity = $this->senderResolver->resolve($this->scopeConfig->getValue(
    'sgecomoutofstock/outofstocksubscription/identity',
    \Magento\Store\Model\ScopeInterface::SCOPE_STORE
));

...

The variable $identity will contain an array with the name and the email.

Your Answer

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

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