Magento:在Custom Observer中发送自定义交易电子邮件

时间:2012-11-04 20:35:36

标签: email events magento smtp transactional

我正在尝试在管理员手动取消订单时发送电子邮件。我正在使用order_cancel_after事件,我的观察者方法运行正常。

但是我的电子邮件没有被解雇。尽管所有代码都已运行,但我得到了以下异常(上图)。

exception 'Zend_Mail_Protocol_Exception' with message 'No recipient forward path has been supplied' in /home/mydomain/www/loja/lib/Zend/Mail/Protocol/Smtp.php:309

我测试了在我的订单观察员上发送新电子邮件:$order->sendNewOrderEmail(),并且新订单电子邮件已正确到达,因此我的SMTP就可以了。

观察员的代码:

class Spalenza_Cancelorder_Model_Observer
{
    public function enviamail(Varien_Event_Observer $observer)
    {
        $order = $observer->getOrder();
        if ($order->getId()) {
            try {
                $translate  = Mage::getSingleton('core/translate');
                $email = Mage::getModel('core/email_template');
                $template = 16;//Mage::getModel('core/email_template') ->loadByCode('Cancelamento Manual by Denis')->getTemplateId();
                Mage::log('Codigo do template: '.$template,null,'events.log');

                $sender  = array(
                'name' => Mage::getStoreConfig('trans_email/ident_support/name', Mage::app()->getStore()->getId()),
                'email' => Mage::getStoreConfig('trans_email/ident_support/email', Mage::app()->getStore()->getId())
                );

                Mage::log($sender,null,'events.log');

                $customerName = $order->getShippingAddress()->getFirstname() . " " . $order->getShippingAddress()->getLastname();
                $customerEmail = $order->getPayment()->getOrder()->getEmail();

                $vars = Array( 'order' => $order );

                $storeId = Mage::app()->getStore()->getId(); 

                $translate  = Mage::getSingleton('core/translate');
                Mage::getModel('core/email_template')
                  ->sendTransactional($template, $sender, $customerEmail, $customerName, $vars, $storeId);
                $translate->setTranslateInline(true);

                Mage::log('Order successfully sent',null,'events.log');
            } catch (Exception $e) {
                Mage::log($e->getMessage(),null,'events.log');
            }
        } else {
            Mage::log('Order not found',null,'events.log');
        }
    }
}

Magento版本:1.5.1.0

1 个答案:

答案 0 :(得分:2)

这一行

$customerEmail = $order->getPayment()->getOrder()->getEmail();

应该是

$customerEmail = $order->getPayment()->getOrder()->getCustomerEmail();

您应该注意错误消息的内容并检查变量的输出。