magento email:快速实现发送自定义邮件

当我们对magento email机制有一定的了解之后,便可以在模块中使用自定义邮件模板快速实现发送邮件功能!登入后台system->Transactional Emails,单击右上角Add New Template,选择一个已存在的template,单击Load Template

修改Template Information的内容,包括Template Name ,Template Subject ,Template Content (可以在原有内容上修改,也可以重新清空写),Template Styles这几项内容。

修改完毕后,单击右上角Save Template,找到最新的那条记录,就是我们刚刚加的,记下id为27;

进入mysql 找到table core_config_data,执行下面SQL

Thank you for reading this post, don't forget to subscribe!
  1. INSERT INTO `magento`.`core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`) VALUES (NULL'default''0''customer/test/test_template''27');

path可以自己定义,但是自己要记得我们这里随便定义为customer/test/test_template,value的值是27,就是上面刚刚我们新加的那条记录的ID。

最后就可以在模块中使用这个email模板了,code和之前文章里介绍的没什么区别,区别就在第一句 如下所示

  1. define('EMAIL_TEMPLATE'"customer/test/test_template");
  2. $mailSubject = 'my subject';
  3. $sender = Array('name'  => 'Customer Service',
  4.             'email' => 'mail@test.com');
  5. $to = array('service@test.com');
  6. /*This is optional*/
  7. $storeId = Mage::app()->getStore()->getId();
  8. $template = Mage::getStoreConfig(EMAIL_TEMPLATE);
  9. $mailConfirm = Mage::getModel('core/email_template');
  10. $translate  = Mage::getSingleton('core/translate');
  11. $mailConfirm ->setTemplateSubject($mailSubject)
  12.          ->sendTransactional($template$sender$to'',
  13.                                   Array('subject'=>$mailSubject,'customer'=>$customer),$storeId);
  14. $translate->setTranslateInline(true);

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注