Question

Im trying to send a transactional email in my modules controller and configure it in the magentos backend.

Here is my try:

in my config.xml

   under config/global

    <template>
        <email>
            <customer_lowerprice_mail_toshop_template
                translate="label" module="telllowerpricelink">

                <label>The mail from the TellLowerPriceForm to the shop</label>
                <file>tellLowerPriceLink/toShopMail.html</file>
                <type>html</type>
            </customer_lowerprice_mail_toshop_template>
        </email>
    </template>

in my system.xml

<?xml version="1.0" encoding="UTF-8"?>
    <config>
    <sections>
    <customer translate="label" module="telllowerpricelink">
                <groups>
                    <lowerprice_mail translate="label">
                        <label>Emails to tell a lower price</label>
                            <frontend_type>text</frontend_type>
                                <sort_order>5</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>0</show_in_website>
                                <show_in_store>0</show_in_store>
                                <fields>
                                    <toshop_template translate="label">
                                        <label>Template for the lower price mail which will be sent to the shop</label>
                                        <frontend_type>select</frontend_type>
                                        <source_model>adminhtml/system_config_source_email_template</source_model>
                                        <sort_order>3</sort_order>
                                        <show_in_default>1</show_in_default>
                                        <show_in_website>1</show_in_website>
                                        <show_in_store>1</show_in_store>
                                    </toshop_template>
                                </fields>
                            </lowerprice_mail>
                        </groups>
                    </customer>
                </sections>
            </config>

in my install-0.1.0.php

$configValuesMap = array(
        'customer/lowerprice_mail/toshop_template' =>
        'customer_lowerprice_mail_toshop_template',
);

foreach ($configValuesMap as $configPath=>$configValue) {
    $installer->setConfigData($configPath, $configValue);
}

and finally my controller:

    $this->toShopTemplateId = Mage::getStoreConfig('customer/lowerprice_mail/toshop_template');
    var_dump($this->toShopTemplateId);
// output: customer_lowerprice_mail_toshop_template

    $this->toShopSubject = 'my test subject';

        /* Will be set with the submitted mailaddress of the user */
    $this->toShopSender = 'test@me.com';
    $this->toShopRecipients = 'test2@me.com';
    $toShopMailVars = Array(
    );

    /* instantiating the mailtemplatemodel and sending it */
    $toShopMail = Mage::getModel('core/email_template')
            ->setTemplateSubject($this->toShopSubject);
    var_dump($toShopMail->getId());
    //output: NULL

So why I do not get the transactional mail template with the ID which appears in the magento backend in my configuration field? Sorry when its obvious

Thanks a lot

Was it helpful?

Solution

You shoul use sendTransactional method. Like:

$mail = Mage::getModel('core/email_template');
$mail->setDesignConfig(array('area' => 'frontend', 'store' => Mage::app()->getStore()->getId()))
     ->sendTransactional(
                        Mage::getStoreConfig('customer/lowerprice_mail/toshop_template'),
                        $sender,
                        $email,
                        null,
                        array(
//params array
                ));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top