我試圖在管理員手動取消訂單時發送電子郵件。我使用的是order_cancel_after事件,我的觀察者方法運行良好。Magento:在自定義觀察器中發送自定義事務電子郵件
但我的電子郵件沒有被解僱。儘管運行了所有代碼,但我得到以下異常(上述)。
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
您是否將該模板添加到管理員 - >交易電子郵件(id 16),因爲它似乎沒有在您的config.xml中有默認值 –
是的,我做到了。交易電子郵件16存在。 –