通过Magento发送电子邮件

时间:2012-03-22 20:08:11

标签: email magento

我在一些博客文章中看到,这是在Magento发送电子邮件的常用方式,但我已经为我的生活,不知道为什么这封电子邮件不是在1.10发送的!这是我的方法:

protected function _emailCode($code, $invoice) {

    $order = $invoice->getOrder();
    // Transactional Email Template's ID
    $templateId = 1;

    // Set sender information
    $senderName = Mage::getStoreConfig('trans_email/ident_support/name');
    $senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
    $sender = array('name' => $senderName,
                'email' => $senderEmail);

    // Set recepient information
    $recepientEmail = $order->getCustomerEmail();
    $recepientName = $order->getCustomerName();     

    // Get Store ID
    $storeId = Mage::app()->getStore()->getId();

    // Set variables that can be used in email template
    $vars = array('voucherCode' => $code);

    $translate  = Mage::getSingleton('core/translate');

    // Send Transactional Email
    Mage::getModel('core/email_template')
        ->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);

    $translate->setTranslateInline(true);
}

我应该注意,电子邮件在Magento的其他部分工作,所以sendmail工作正常,所有这些,我的所有变量都是正确定义的,而不是空的。

谢谢!

1 个答案:

答案 0 :(得分:0)

您确定存在ID = 1的交易电子邮件吗? 尝试设置$templateId='sales_email_order_template'
这是一个默认模板,应该适合工作脚本。 检查exception.log也是。