0

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('[email protected]');
$emailTemplate->send('[email protected]','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

8
  • $emailTemplate->send('[email protected]','Forgot Password',,$storeId=null); not sure where is problem but try that clear your cache too Commented Apr 11, 2016 at 10:46
  • i got one more error now in my system.xml 2016-04-11T10:51:24+00:00 ERR (3): Recoverable Error: Argument 3 passed to Aschroder_SMTPPro_Model_Email_Template::send() must be of the type array, null given, called in /var/www/html/MMM/app/code/local/$ Commented Apr 11, 2016 at 10:53
  • $cus=array(); $emailTemplate->send('[email protected]','Forgot Password',$cus ,$storeId=null); try that Commented Apr 11, 2016 at 10:57
  • sir it removed the latest error is still same mail is not going Commented Apr 11, 2016 at 10:59
  • did you the custom email it is going simple email? Commented Apr 11, 2016 at 10:59

1 Answer 1

2

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('[email protected]');
$emailTemplateVariables = array();
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
$emailTemplate->send('[email protected]','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('');
}
14
  • thank you very much for your help but it is not working can you tell me is my template is correct because in aschroder_smtppro.log m getting Email is not valid for sending, this is a core error that often means there's a problem with your email templates. Commented Apr 11, 2016 at 11:21
  • did you load the email in admin panel and check that? Commented Apr 11, 2016 at 11:30
  • it is loading and showing the preview Commented Apr 11, 2016 at 11:33
  • remove this and try with simple text {{store url="customer/account/"}} Commented Apr 11, 2016 at 11:37
  • still not working Commented Apr 11, 2016 at 11:46

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.