0

I get the following error: "exception 'exception' with message 'this letter cannot be sent.' magento" , in magento php. below is the code i have used.

Observer.php

<?php
class Metro_Purchaseorder_Model_Observer extends Mage_Core_Model_Abstract
{ 
    public function shipmentEmail($observer)
                {
                    $event = $observer->getEvent();
                    if(!$order = $event->getOrder())
                    {
                                    $order_Id = Mage::getSingleton('checkout/type_onepage')->getCheckout()
                      ->getLastOrderId();
                                    $order = Mage::getModel('sales/order')->load($order_Id);
                                    $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
                    }
                    $payment = $order->getPayment()->getMethod();
                    $storeId = $order->getStoreId();
                    $emailTemplate  = Mage::getModel('core/email_template')->loadDefault('custom_email_po_template');   
                    $emailTemplateVariables = array();                  
                    $emailTemplateVariables['myvar1'] = 'Branko';
                    $emailTemplateVariables['myvar2'] = 'Ajzele';
                    $emailTemplateVariables['myvar3'] = 'ActiveCodeline';
                    $emailTemplateVariables['storeid'] = $storeId;                  
                    $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
                    /*  $emailTemplate->setSenderName('MetroCC');
                    $emailTemplate->setSenderEmail('info@metrocc.com');
                    $emailTemplate->setTemplateSubject($this->__('PO Test mail'));  */
                    //send mail
                    $emailTemplate->send('sachin301190@gmail.com', 'sachin', $emailTemplateVariables); 
                    return true;
                }       
}

in Config.xml

------------------------------
<?xml version="1.0"?>
<config>
   <modules>
        <Metro_Purchaseorder>
            <version>0.1.0</version>
        </Metro_Purchaseorder>
    </modules>
          <frontend>
            <events>
                <checkout_onepage_controller_success_action>
                    <observers>
                        <purchaseorder_observer>
                            <type>singleton</type>
                            <class>Metro_Purchaseorder_Model_Observer</class>
                            <method>shipmentEmail</method>
                        </purchaseorder_observer>
                    </observers>
                </checkout_onepage_controller_success_action>
            </events>
            </frontend>
                <global>
                  <template>
                        <email>                     
                                <purchaseorder_custom_email1 translate="label" module="purchaseorder">
                                        <label>Purchaseorder module</label>
                                        <file>sales/purchaseorder_custom_email1.html</file>
                                        <type>html</type>
                                </purchaseorder_custom_email1>
                        </email>
                        </template>      
                  </global>    
</config>

Please help me in correcting the above error for sending custom email template

0

Sachin,You issue with event parameter.checkout_onepage_controller_success_action give last order ids in a array . You can easy check at class Mage_Checkout_OnepageController at function successAction.

Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId)));

your observer code is

<?php
class Metro_Purchaseorder_Model_Observer {

    public function shipmentEmail(Varien_Event_Observer $observer) 
        {
        $orderIds = $observer->getEvent()->getOrderIds();
        if (empty($orderIds) || !is_array($orderIds)) {
            return;
        }
        foreach($orderIds as $eachOrderId){
             $order = Mage::getModel('sales/order')->load($eachOrderId);
            try {
                    $order = Mage::getModel('sales/order')->load($eachOrderId);
                    $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
                    $payment = $order->getPayment()->getMethodInstance()->getCode();
                    $storeId = $order->getStoreId();
                    $emailTemplate  = Mage::getModel('core/email_template')->loadDefault('custom_email_po_template');   
                    $emailTemplateVariables = array();                  
                    $emailTemplateVariables['myvar1'] = 'Branko';
                    $emailTemplateVariables['myvar2'] = 'Ajzele';
                    $emailTemplateVariables['myvar3'] = 'ActiveCodeline';
                    $emailTemplateVariables['storeid'] = $storeId;                  
                    $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
                    /*  $emailTemplate->setSenderName('MetroCC');
                    $emailTemplate->setSenderEmail('info@metrocc.com');
                    $emailTemplate->setTemplateSubject($this->__('PO Test mail'));  */
                    //send mail
                    $emailTemplate->send('sachin301190@gmail.com', 'sachin', $emailTemplateVariables); 
                    return true;


                }catch (Mage_Core_Exception $e) {
            }
        break;
        }
            return $this;
        }

}
  • Hi Amit thanks for your reply. I tried your code in Observer.php I get : Fatal error: Call to a member function getMethod() on boolean – Sushivam Feb 26 '15 at 11:48
  • Could you please suggest on what care has to be taken for the following error on line 17 in the above code for Fatal error: Call to a member function getMethod() on boolean – Sushivam Feb 26 '15 at 12:34
  • check again............. – Amit Bera Feb 26 '15 at 12:36
0

You commented out some important code:

/*  $emailTemplate->setSenderName('MetroCC');
$emailTemplate->setSenderEmail('info@metrocc.com');
$emailTemplate->setTemplateSubject($this->__('PO Test mail'));  */

Emails can only be sent if the sender name, sender email and template subject are all set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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