是否曾想过用Magento内置的电子邮件功能发送邮件?是否想在Magento中做些什么的时候碰壁?好吧,我已经知道答案了。总之,Magento发送邮件被证实只要几个小时跟踪Magento代码。 ... /* * 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}}. </div>(责任编辑:好模板) |