出处:http://koda.iteye.com/blog/623678
Magento的Mage::getModel('core/email_template')模型可用来发信。
步骤I.
在你的模块(其实任意Module都可以)的etc/config.xml的根标签<config>下添加代码
1. <default> 2. <{限定名1}> 3. <{限定名n}> 4. <enabled>1</enabled> 5. <template>{email模板标签名}</template> 6. </{限定名n}> 7. </限定名> 8. </default> 9. <global> 10. <template> 11. <email> 12. <{{email模板标签名} translate="label" module="{模块名}"> 13. <label>{任何标识性名}</label> 14. <file>{email模板html文件名}</file> 15. <type>html</type> 16. </{email模板标签名> 17. </email> 18. </template> 19. </global>
1. <default> 2. <customer_email> 3. <services_request> 4. <enabled>1</enabled> 5. <template>customer_email_service_template</template> 6. </services_request> 7. </customer_email> 8. </default> 9. <global> 10. <template> 11. <email> 12. <customer_email_service_template translate="label" module="sales"> 13. <label>Customer Services Request</label> 14. <file>customer_services.html</file> 15. <type>html</type> 16. </customer_email_service_template> 17. </email> 18. </template> 19. </global>步骤II.
1. /* @var $translate Mage_Core_Model_Translate */ 2. $translate = Mage::getSingleton('core/translate'); 3. $translate->setTranslateInline(false); 4. 5. $storeId = Mage::app()->getStore()->getId(); 6. $template = Mage::getStoreConfig('customer_email/services_request/template', $storeId); 7. $recipient = array( 8. 'name' => 'Baby', 9. 'email' => '[email protected]' 10. ); 11. $sender = array( 12. 'name' => 'Koda Guo', 13. 'email' => '[email protected]' 14. ); 15. 16. $mailTemplate = Mage::getModel('core/email_template'); 17. $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$storeId)) 18. ->sendTransactional( 19. $template, 20. $sender, 21. $recipient['email'], 22. $recipient['name'], 23. array( // parameters to email 24. 'param1'=> 'abc', 25. 'param2'=> 'def', 26. 'param3'=> 'ghi' 27. ) 28. ); 29. $translate->setTranslateInline(true);