我正在开发一个模块,该模块将在订单完成7天后发送电子邮件。我一直在发送电子邮件。我可以在管理员中看到交易电子邮件中的电子邮件模板。但是电子邮件没有发送。
这是我的confix.xml部分,用于包含电子邮件模板。
<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>
这就是我在控制器操作中发送电子邮件的方式
$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('sender@test.com');
try {
$emailTemplate->send('myemail@gmail.com', 'bla bla',$emailTemplateVariables);
} catch (Exception $e) {
echo $e->getMessage();
}
我不知道为什么它不起作用。
答案 0 :(得分:29)
$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;
}
答案 1 :(得分:4)
将您的etc / config.xml代码更改为:
<template>
<email>
<recurring_order_email_template>
<label>Recurring order email</label>
<file>coeus_recurring_order_email.html</file>
<type>html</type>
</recurring_order_email_template>
</email>
</template>
将您的控制器代码更改为以下内容:
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('recurring_order_email_template');
$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('sender@test.com');
try {
$emailTemplate->send($recipientEmail, $senderName, $emailTemplateVariables);
} catch (Exception $e) {
echo $e->getMessage();
}
更改您的$ recipientEmail,$ senderName&amp; $ emailTemplateVariables根据您的需要。
要加载电子邮件模板,您必须在
之后指定标记名称<template>
<email>
</email>
</template>
您在config.xml中提供的
答案 2 :(得分:1)
我认为你在这里犯了错误。
$emailTemplate = Mage::getModel('core/email_template')->loadDefault('coeus_recurring_order_email');
试试这个
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('recurring_order_email_template');
要加载电子邮件模板,您必须提供您在config.xml中提供的标记名称
代码中例如:
使用
<recurring_order_email_template>
加载电子邮件模板