本文介绍了自定义邮件发送在magento自定义模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个在订单完成7天后发送电子邮件的模块。我被困在发送电子邮件。我可以在管理员中下载交易电子邮件中看到电子邮件模板。但是电子邮件没有发送。
I am working on a module that will send an email after 7 days of order completion. I'm stuck on sending emails. I can see the email template in transactional emails drop down in admin. But the email is not being sent.
这是我的confix.xml部分,用于包含电子邮件模板。
Here is my confix.xml part for including email template.
<template>
<email>
<recurring_order_email_template translate="label">
<label>Recurring order email</label>
<file>coeus_recurring_order_email.html</file>
<type>html</type>
</recurring_order_email_template>
</email>
</template>
这是我在控制器操作中发送电子邮件的方式
and this is how I am sending email in controller action
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('coeus_recurring_order_email');
$emailTemplateVariables = array();
$emailTemplateVariables['var1'] = 'var1 value';
$emailTemplateVariables['var2'] = 'var 2 value';
$emailTemplateVariables['var3'] = 'var 3 value';
$emailTemplate->getProcessedTemplate($emailTemplateVariables);
$emailTemplate->setSenderName('sender name');
$emailTemplate->setSenderEmail('[email protected]');
try {
$emailTemplate->send('[email protected]', 'bla bla',$emailTemplateVariables);
} catch (Exception $e) {
echo $e->getMessage();
}
我不知道为什么它不工作。
I don't know why its not working.
推荐答案
$emailTemplate = Mage::getModel('core/email_template')->loadDefault('recurring_order_email_template');
//Getting the Store E-Mail Sender Name.
$senderName = Mage::getStoreConfig('trans_email/ident_general/name');
//Getting the Store General E-Mail.
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
//Variables for Confirmation Mail.
$emailTemplateVariables = array();
$emailTemplateVariables['name'] = $customerName;
$emailTemplateVariables['email'] = $customerEmail;
//Appending the Custom Variables to Template.
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
//Sending E-Mail to Customers.
$mail = Mage::getModel('core/email')
->setToName($senderName)
->setToEmail($customerEmail)
->setBody($processedTemplate)
->setSubject('Subject :')
->setFromEmail($senderEmail)
->setFromName($senderName)
->setType('html');
try{
//Confimation E-Mail Send
$mail->send();
}
catch(Exception $error)
{
Mage::getSingleton('core/session')->addError($error->getMessage());
return false;
}
这篇关于自定义邮件发送在magento自定义模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!