2

I created an email template which appears to be set up correctly. I say this based on it appearing in the System->Transactional Emails section. I tested this by changing the label a few times to make sure and all seemed as it should be.

Issue: when I try to send the email it doesn't send. It is being called from the indexController.php of the same module as the config.xml where I list the email template. The indexController.php itself seems fine to me because it works apart from this.

email template (app/locale/en_US/template/email/sales/new_mto.html)

 <div>
 <h1>ActiveCodeline custom email example by Branko Ajzele</h1>
  <p>Hi there {{var myvar1}} {{var myvar2}} from {{var myvar3}}. This is just some example template to test custom email module.</p>
</div>

config.xml section

 <?xml version="1.0" encoding="UTF-8"?>

 <config> 

<modules>

    <Company_Mto>
        <version>0.0.1</version>
    </Company_Mto>

</modules>

<adminhtml>
    <layout>
        <updates>
            <slider>
                <file>mto.xml</file>
            </slider>
        </updates>
    </layout>
</adminhtml>

<frontend>
    <routers>
        <Mto>
            <use>standard</use>
            <args>
                <module>Company_Mto</module>
                <frontName>Mto</frontName>
            </args>
        </Mto>
    </routers>
</frontend>

<global>
    <template>
        <email>
            <mto_index_index translate="label" module="mto">
                <label>New MTO</label>
                <file>sales/new_mto.html</file>
                <type>html</type>
            </mto_index_index>
        </email>
    </template>

    <helpers>
        <mto>
            <class>Company_Mto_Helper</class>
        </mto>
    </helpers>
</global>

</config>

indexController.php (from same module as the config.xml where the email template is referenced above

 $emailTemplate  = Mage::getModel('core/email_template')->loadDefault('new_mto');    
 $emailTemplateVariables = array();
 $emailTemplateVariables['myvar1'] = 'Branko';
 $emailTemplateVariables['myvar2'] = 'Ajzele';
 $emailTemplateVariables['myvar3'] = 'ActiveCodeline';
 $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
 $result = $emailTemplate->send('myemail@changedforprivacy.com','John Doe', $emailTemplateVariables);
 echo '<br>' . $result;

I have followed this tutorial and looked at some other email questions (which I know have already been asked) but I can't figure out where I'm going wrong.

9
  • Try loadDefault('new_mto') to loadDefault('mto_index_index'), but I would not recommend using this example because making changes in System->Transactional Emails section will not load the update because you dont have a variable in your system.xml Sep 18, 2014 at 15:19
  • loadDefault('mto_index_index') didn't work. Any links that I could look at with an example of what you mean? @R.S Sep 18, 2014 at 15:38
  • Can you add your full config.xml file Sep 18, 2014 at 16:07
  • @R.S just added it, cheers. Sep 18, 2014 at 16:12
  • 1
    Possible duplicate of New order email confirmation not being sent Jul 26, 2019 at 4:54

1 Answer 1

3

I changed the email section a little in the config.xml

  <template>
        <email>
            <new_mto translate="label" module="mto">
                <label>New MTO</label>
                <file>sales/new_mto.html</file>
                <type>html</type>
            </new_mto>
        </email>
    </template>

and called it a little differently

 try {
            $storeObj = Mage::getModel('core/store')->load(1);
            $customerEmailId = 'thomas@email.co.uk';
            $customerFName = 'john';
            $customerLName = 'doe';

            $emailTemplate = Mage::getModel('core/email_template')
                    ->loadDefault('new_mto');

            $emailTemplateVariables = array();
            $emailTemplateVariables['order'] = '$order';
            $emailTemplateVariables['store'] = '$storeObj';
            $emailTemplateVariables['payment_html'] = '$method';


            $emailTemplate->setSenderName('Magento');
            $emailTemplate->setSenderEmail('sender.com');
            $emailTemplate->setType('html');
            $emailTemplate->setTemplateSubject('Add a subject');
            $emailTemplate->send($customerEmailId, $customerFName . $customerLName, $emailTemplateVariables);
            return true;
        } catch (Exception $e) {
            $errorMessage = $e->getMessage();
            return $errorMessage;
        }

This now works for me exactly as I wanted.

Your Answer

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

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