Magento – Not able to send email using custom template in magento 1.9.2 community edition

emailemail-templatesmagento-1.9

Hello guys i am trying to send an email in magento using custom email templates. But I am getting exception I have installed SMTP Pro Extension.

I am listing code here:-

My config.xml

<template>
  <email>
    <custom_abc_email_template  module="custom_abc">
      <label>Custom Template</label>
      <file>custom_abc_templates/customTemplate.html</file>  // this specifies the path where the custom template is located
      <type>html</type>
    </custom_abc_email_template>
  </email>
</template>

code of my controller action

$emailTemplate  = Mage::getModel('core/email_template')->loadDefault('custom_abc_email_template');
$emailTemplate->setSenderName('custom template');
$emailTemplate->setSenderEmail('abc@demomail.com');
$emailTemplate->send('abc@demomail.com','Forgot Password');

My Template file code

<table cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td class="action-content">
            <h1>Custom Abc,</h1>
            <p><strong>Your new password is:</strong> trolled</p>
            <p>You can change your password at any time by logging into <a href="{{store url="customer/account/"}}">your account</a>.</p>
        </td>
    </tr>
</table>

In exception.log

2016-04-11T10:03:18+00:00 ERR (3): exception 'Exception' with message
'This letter cannot be sent.' in /var/www/html/MMM/app/code/local/Aschroder/SMTPPro/Model/Email/Template.php:40

In aschroder_smtppro.log

2016-04-11T10:03:18+00:00 DEBUG (7): Email is not valid for sending, 
this is a core error that often means there's a problem with your email templates.

setting of email in backend
enter image description here

Best Answer

use below code you were not processing the template..

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

$emailTemplate->setSenderName('custom template');
$emailTemplate->setSenderEmail('abc@demomail.com');
$emailTemplateVariables = array();
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
$emailTemplate->send('abc@demomail.com','Forgot Password', $emailTemplateVariables,$storeId=null);

try to send direct email it is working or not

$html="
put your html content here
blah blah

";
$mail = Mage::getModel('core/email');
$mail->setToName('Your Name');
$mail->setToEmail('Youe Email');
$mail->setBody('Mail Text / Mail Content');
$mail->setSubject('Mail Subject');
$mail->setFromEmail('Sender Mail Id');
$mail->setFromName("Msg to Show on Subject");
$mail->setType('html');// YOu can use Html or text as Mail format

try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
$this->_redirect('');
}
catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send.');
$this->_redirect('');
}
Related Topic