【问题标题】:Magento send email in custom moduleMagento 在自定义模块中发送电子邮件
【发布时间】:2015-05-21 23:01:25
【问题描述】:

我需要创建一个电子邮件模板。此外,我需要将该客户模板加载到另一个 .phtml 文件中并在发送电子邮件之前进行编辑。仅编辑后我需要发送电子邮件。谁能帮我怎么做?

我搜索并尝试了这个,但我只找到了与发送电子邮件相关的文章,而没有编辑现有的电子邮件模板。

示例:http://www.caritorsolutions.com/blog/158-send-email-from-custom-module-in-magento

【问题讨论】:

  • 您可以在后端创建一个新的交易电子邮件,并分配变量来容纳您的自定义字段/值/html。然后可以在您的代码中的任何位置调用此电子邮件模板,并与您的动态数据一起发送。

标签: magento email-templates


【解决方案1】:

您可以在进入系统 > 交易电子邮件时创建电子邮件模板。您输入的名称是该模板的唯一标识符。

<?php

$templateName = 'template_name_you_put_in_in_the_backend';

$to = 'johndoe@example.com';
$customerName   = 'John Doe';

// Load our template by template_id
$emailTemplate  = Mage::getModel('core/email_template')->loadDefault($templateId);

$vars = array(
    'customer_name' => $customerName
    // Other vars that can be used in the mplate
);

// Store sends it
$senderName = Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_STORE_NAME);
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
$emailTemplate->setSenderName($senderName);
$emailTemplate->setSenderEmail($senderEmail); 

//Send the email!
$emailTemplate->send($to, $customerName, $emailTemplateVariables);

您当然可以通过 System > Transactional Emails 编辑此文件。如果这不是您的意思,您能否通过“编辑现有电子邮件模板”澄清您的意思?

【讨论】:

    猜你喜欢
    • 2014-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多