Magento自定义邮件

redmaomail 2024-07-24 18:13 阅读数 66 #Magento

红帽云邮外贸主机

是否曾想过用Magento内置的电子邮件功能发送邮件?是否想在Magento中做些什么的时候碰壁?好吧,我已经知道答案了。总之,Magento发送邮件被证实只要几个小时跟踪Magento代码。那么,我要创建名为activecodeline_custom_email1.html电子邮件,我想在它运行时传几个变量给它,我要以编程的方式发送电子邮件。

下面就是:

...
/*
 * Loads the html file named 'custom_email_template1.html' from
 * app/locale/en_US/template/email/activecodeline_custom_email1.html
 */ 
$emailTemplate  = Mage::getModel('core/email_template')
						->loadDefault('custom_email_template1');					

//Create an array of variables to assign to template
$emailTemplateVariables = array();
$emailTemplateVariables['myvar1'] = 'Branko';
$emailTemplateVariables['myvar2'] = 'Ajzele';
$emailTemplateVariables['myvar3'] = 'ActiveCodeline';
 
/**
 * The best part :)
 * Opens the activecodeline_custom_email1.html, throws in the variable array 
 * and returns the 'parsed' content that you can use as body of email
 */
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
 
/*
 * Or you can send the email directly, 
 * note getProcessedTemplate is called inside send()
 */
$emailTemplate->send('john@someemail.com','John Doe', $emailTemplateVariables);
...

为了让上面的代码工作,你需要在config.xml中添加下面的代码:

...
<global>      
	<template>
		<email>
			<custom_email_template1 module="SampleModule1">
				<label>ActiveCodeline custom email module</label>
				<file>activecodeline_custom_email1.html</file>
				<type>html</type>
			</custom_email_template1>
		</email>
	</template>
</global>  
...

不要忘了邮件模版app/locale/en_US/template/email/activecodeline_custom_email1.html.

<!--@subject ActiveCodeline custom email module @-->
 
<div>
<h1>ActiveCodeline custom email example by Branko Ajzele</h1>
<p>Hi there {{var myvar1}} {{var myvar2}} from {{var myvar3}}. This is just some example template to test custom email module.</p>
</div>

电商网站开发服务


红帽云邮外贸主机

分享到:
版权声明:本站内容源自互联网,如有内容侵犯了你的权益,请联系删除相关内容。
    红帽云邮外贸主机
热门
    红帽云邮外贸主机
    红帽云邮外贸主机