如何使用自定义电子邮件模板发送电子邮件

时间:2014-09-10 19:58:08

标签: magento templates sendmail

我正在为废弃订单创建模板。 但是当我尝试使用创建的模板时,发送一封空白电子邮件,更多模板显示在:System/Transactional Email

模板

temaplate是order_update.htmltest_order_update.html en_US/template/email/sales/的副本<global> <template> <email> <custom_template module="mymodule"> <label>Abandoned Transactions</label> <file>sales/test_order_update.html</file> <type>html</type> </custom_template> </email> </template> </global>

Config.xml - 这是有效的

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

    $emailTemplate = Mage::getModel('core/email_template');
    $emailTemplate->loadDefault('test_order_update');
    $emailTemplate->setTemplateSubject('my subject here');

    $email = Mage::getStoreConfig('trans_email/ident_sales/email');
    $name = Mage::getStoreConfig('trans_email/ident_sales/name');

    $emailTemplate->setSenderName($name, $storeId);
    $emailTemplate->setSenderEmail($email, $storeId);

    $emailTemplateVariables['username']  = ' something';
    $emailTemplateVariables['store_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

    $emailTemplate->send('myemail@gmail.com', 'name...', $emailTemplateVariables);
?>

拍摄 - 请勿加载模板

Sender: Sales <sales@example.com>
Subject: my subject here
Content: 

收到电子邮件

{{1}}

1 个答案:

答案 0 :(得分:3)

尝试替换

$emailTemplate->loadDefault('test_order_update');

$emailTemplate->loadDefault('custom_template');

因为要加载电子邮件模板,您必须提供您在config.xml中提供的标记名称

在发送邮件前添加以下行

$emailTemplate->getProcessedTemplate($emailTemplateVariables);

如果您的模板是order_update.html的副本,您还需要将订单对象作为电子邮件参数传递。

相关问题