我正在嘗試爲magento 1.7創建一個模塊,只要新用戶訂閱新聞通訊,它就會向管理員發送通知郵件。到目前爲止,我已經成功地發送了郵件。但是,我的代碼沒有將getEmail和getId值顯示在發送給管理員的郵件中。如果任何人都可以告訴我哪裏出錯了,那將會很棒。這裏是代碼:如何在magento中創建管理通知郵件訂閱新聞訂閱
應用程序/代碼/本地/通知/六必居的/ etc/config.xml中
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Notify_Biju>
<version>0.1.0</version>
</Notify_Biju>
</modules>
<global>
<models>
<Notify_Biju>
<class>Notify_Biju_Model</class>
</Notify_Biju>
</models>
<template>
<email>
<newsletter_alert_template translate="label" module="n">
<label>Newsletter Alert to Admin</label>
<file>newsletter_subscription_notify.html</file>
<type>html</type>
</newsletter_alert_template>
</email>
</template>
</global>
<frontend>
<events>
<newsletter_subscriber_save_after>
<observers>
<Notify_Biju_Model_Observer>
<type>singleton</type>
<class>Notify_Biju_Model_Observer</class>
<method>newsletteralert</method>
</Notify_Biju_Model_Observer>
</observers>
</newsletter_subscriber_save_after>
</events>
</frontend>
</config>
應用程序/代碼/本地/通知/六必居/型號/ Observer.php
<?php
class Notify_Biju_Model_Observer {
const XML_PATH_EMAIL_TEMPLATE = 'newsletter_alert_template';
public function newsletteralert($observer){
$eventname=$observer->getEvent()->getName();
$subscriber=$observer->getEvent()->getSubscriber();
$email=$subscriber->getEmail();
$id=$subscriber->getId();
$emailtemplate=Mage::getModel('core/email_template')->loadDefault(self::XML_PATH_EMAIL_TEMPLATE);
$sender=array();
$sender['name']="admin";
$sender['email']="[email protected]";
try{
$emailtemplate->sendTransactional(
self::XML_PATH_EMAIL_TEMPLATE,
$sender,
'[email protected], [email protected]', // email id of website/store admin
'admin',
array('subscirber'=>$subscriber)
);
}
catch(Mage_Core_Exception $e){
// echo $e->getMessage();
Mage::log($e->getMessage(),null,'newsletter.log');
}
}
}
應用的/ etc /模塊/ Notify_Biju.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Notify_Biju>
<active>true</active>
<codePool>local</codePool>
</Notify_Biju>
</modules>
</config>
應用程序/區域/ EN_US /模板/電子郵件/ newsletter_subscription_notify.html
<[email protected] Newsletter Subscription Alert @-->
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td valign="top" style="padding:20px 0 20px 0">
<!-- (header starts here) -->
<table bgcolor="#FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
<h3 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;"></h3>
</td>
</tr>
<tr>
<td valign="top"><h3 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;">Dear Admin </h3>
<p> Congratulations! A new subscriber has registered for Newsletter. Please login to the admin back-end to manage subscriptions.</p>
<p>Subscriber Email: {{var subscriber.getEmail()}}</p>
<p>Subscriber ID: {{var subscriber.getId()}}</p>
<br>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>