Magento – New Email Template Not Sending

email

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.

Best Answer

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.