简体   繁体   English

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

[英]How to send email with a custom email template

I am creating a template for abandoned orders. 我正在为废弃的订单创建模板。 But when I try to use the template created, the send a blank email, more the template appears in: System/Transactional Email 但是,当我尝试使用创建的模板时,发送空白电子邮件,则更多模板显示在: System/Transactional Email

Template 模板

The temaplate is a copy of order_update.html with name test_order_update.html in en_US/template/email/sales/ 该temaplate是副本order_update.html与名test_order_update.htmlen_US/template/email/sales/

Config.xml - This is working Config.xml-这正在工作

<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>

Shooting - Do not load the template 拍摄-不要加载模板

<?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);
?>

Email received 收到邮件

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

try replacing 尝试更换

$emailTemplate->loadDefault('test_order_update');

with

$emailTemplate->loadDefault('custom_template');

because to load a email template you have to give the tag name that you provide in the config.xml 因为要加载电子邮件模板,您必须提供在config.xml中提供的标签名称

also add following line before sending mail 在发送邮件之前也添加以下行

$emailTemplate->getProcessedTemplate($emailTemplateVariables);

if your template is copy of order_update.html you also need to pass the order object as teh email parameter. 如果您的模板是order_update.html的副本,则还需要将订单对象作为电子邮件参数传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM