我正在尝试为magento 1.7创建一个模块,当新用户订阅简报时,该模块会向管理员发送通知邮件。到目前为止,我已成功收到邮件。但是,我的代码没有将getEmail和getId值显示在发送给admin的邮件中。如果有人可以对我出错的地方有所了解,那就太好了。这是代码:
应用/代码/本地/通知/六必居的/ 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']="biju@talkingpebbles.com";
try{
$emailtemplate->sendTransactional(
self::XML_PATH_EMAIL_TEMPLATE,
$sender,
'biju@talkingpebbles.com, allen@compkraft.com', // 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
<!--@subject 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>
答案 0 :(得分:0)
你有一个错字:
搜索array('subscirber'=>$subscriber)
。
您的“订阅者”拼写错误为“subscirber”
答案 1 :(得分:0)
获取订阅者电子邮件值&amp; id在观察者中,
$subscriber=$observer->getEvent()->getSubscriber() ;
$email=$subscriber->getSubscriberEmail();
$id=$subscriber->getSubscriberId();
$emailtemplate->sendTransactional(
XML_PATH_EMAIL_TEMPLATE,
Mage::getStoreConfig(XML_PATH_CONFIRM_EMAIL_IDENTITY),
'sample@xyz.in', // email id of website/store admin
'admin',
array(
'subscriber_email' => $email,
'subscriber_id' => $id
)
然后在邮件中添加像这样的变量而不是你的行
<p>Subscriber Email: {{var subscriber_email}}</p>
<p>Subscriber ID: {{var subscriber_id}}</p>