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


$emailTemplateVariables = array();
 $emailTemplateVariables['test'] = 'Branko';
 $emailTemplateVariables['name'] = 'Ajzele';
 $emailTemplateVariables['reviewurl'] = Mage::getUrl('test/index/review');

echo $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);

$emailTemplate->send('[email protected]','John Doe', $emailTemplateVariables);

output echo

It is time to review Branko

Hi Ajzele

Click this Make a Review


error


2015-06-17T10:17:10+00:00 ERR (3): 
exception 'Exception' with message 'This letter cannot be sent.' in /var/www/servicecenters/app/code/local/Aschroder/SMTPPro/Model/Email/Template.php:40
6
  • Is template id correct? I doubt your template id is not getting called. Jun 17, 2015 at 10:44
  • It is time to review Branko Hi Ajzele Click this Make a Review this is template out Jun 17, 2015 at 10:50
  • hi Qaisar, How did you solve this issue?
    – Mujahidh
    Jan 9, 2017 at 4:59
  • @mujas just adding the store id Mage::app()->getStore()->getStoreId() in last parameter $emailTemplate->send('[email protected]','John Doe', $emailTemplateVariables,Mage::app()->getStore()->getStoreId()); Jan 9, 2017 at 5:03
  • Thanks you.not working,i also using the same way you used.Do i want to config anything from the back end.Accepted solution also checked in my testing server.
    – Mujahidh
    Jan 9, 2017 at 5:17

2 Answers 2

7

Try this:

So the problem was: !Mage::getStoreConfigFlag('system/smtp/disable') which you can fix up in Admin > System > Configuration > Advanced > System > Mail Sending Settings and change Disable Email Communications to No so the emails are NOT disabled.

Explanation

Look at the /app/code/core/Mage/Core/Model/Email/Template.php.The code throwing this error is:

if (!$this->isValidForSend()) {
    Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted
    return false;
}

Look at isValidForSend():

public function isValidForSend()
{
    return !Mage::getStoreConfigFlag('system/smtp/disable')
        && $this->getSenderName()
        && $this->getSenderEmail()
        && $this->getTemplateSubject();
}

More info.

1
  • 1
    A little error: the correct path is Admin > System > Configuration > System > Mail Sending Settings (no > Advanced)
    – WaPoNe
    Jul 1, 2016 at 10:37
3

For me the Problem was, that I defined a custom email template via config.xml of my own module and forgot to set the comment block with subject and so on.

<!--@subject Welcome, {{var customer.name}}! @-->
<!--@vars
{"store url=\"\"":"Store Url",
"var logo_url":"Email Logo Image Url",
"htmlescape var=$customer.name":"Customer Name",
"store url=\"customer/account/\"":"Customer Account Url",
"var customer.email":"Customer Email",
"htmlescape var=$customer.password":"Customer Password"}
@-->

<!--@styles
@-->
1
  • It was the same for me. I just added <!--@subject Welcome, {{var customer.name}}! @--> on top of my file "/app/locale/es_ES/template/email/sales_new_recurring.html"
    – Eduardo
    Mar 7, 2017 at 18:04

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.