I am creating a custom module with a custom database table using the following tutorial.

This module is a custom contact form, and I would like the settings for that custom contact form to be on a per store basis, meaning, I want the send from email address to be different for each store I create.

Do I need to add specific fields to the database for Magento to pick up on this? Or does Magento do this automagically?

2 Answers 2


You could use the existing behavior of Magento which allows to define and get a contact email address for each store view and depending on the department (sales, customer support, general). You can then use theses specific contact per store view in your custom module.

Here is the configuration backend for email addresses: backend email addresses

And to use this specific email in your custom module, the important part in your case is the $sendervariable. Here is a code sample (check the comment in it, be aware that it is taken from a code of me, so adapt to your needs):

$recipient = $item->getRecipient();
$template = $item->getTemplate();

if (!Mage::getConfig()->getNode(Mage_Core_Model_Email_Template::XML_PATH_TEMPLATE_EMAIL .'/' . $template)){
    Mage::throwException(Mage::helper('customer')->__('Wrong transactional notification email template.'));

$customer = Mage::getModel('customer/customer')->load($customer->getId());
$recipient = array('name' => $customer->getName(), 'email' => $customer->getEmail());
     * $senderType can be support, general, sales, custom1, custom2
     *  You can also replace the array by a string and provide only the string 'general', 'support', etc
    $sender = array(
        'name' => Mage::getStoreConfig('trans_email/ident_' . $senderType . '/name', $storeId),
        'email' => Mage::getStoreConfig('trans_email/ident_' . $senderType . '/email', $storeId)

$translate = Mage::getSingleton('core/translate');

/* @var $emailTemplate Mage_Core_Model_Email_Template */
$emailTemplate = Mage::getModel('core/email_template');

if (Mage::app()->getStore()->isAdmin()) Mage::app()->getLocale()->emulate($storeId);

$variables += array(
    'name' => $customer->getName()

if (Mage::app()->getStore()->isAdmin()) Mage::app()->getLocale()->revert();

$emailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))
    ->sendTransactional($template, // xml path email template


Magento will add these automagically when you define them in your modules system.xml file.

    <label>Some Setting Label</label>

You then retrieve the config value for the store in question via...

Mage::getStoreConfig( '/path/to/setting', $store_id );


public static function getStoreConfig($path, $store = null)
    return self::app()->getStore($store)->getConfig($path);

Which, in turn, calls...


public function getConfig($path)
    if (isset($this->_configCache[$path])) {
        return $this->_configCache[$path];

    $config = Mage::getConfig();

    $fullPath = 'stores/' . $this->getCode() . '/' . $path;
    $data = $config->getNode($fullPath);
    if (!$data && !Mage::isInstalled()) {
        $data = $config->getNode('default/' . $path);
    if (!$data) {
        return null;
    return $this->_processConfigValue($fullPath, $path, $data);

Notice how it's determining the path to the config value based upon the store code here...

$fullPath = 'stores/' . $this->getCode() . '/' . $path;

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.