1

我正在尝试为 magento 1.7 创建一个模块,该模块将在新用户订阅时事通讯时向管理员发送通知邮件。到目前为止,我已成功发送邮件。但是,我的代码没有将 getEmail 和 getId 值显示在发送给管理员的邮件中。如果有人能说明我哪里出错了,那就太好了。这是代码:

app/code/local/Notify/Biju/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>

app/code/local/Notify/Biju/Model/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/modules/Notify_Biju.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Notify_Biju>
            <active>true</active>
            <codePool>local</codePool>
        </Notify_Biju>
    </modules>
</config>

app/locale/en_US/template/email/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>
4

2 回答 2

0

要在观察者中获取订阅者电子邮件值和 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>
于 2014-07-17T07:51:43.720 回答
0

你有一个错字:

搜索array('subscirber'=>$subscriber)

您将“订阅者”拼错为“订阅者”

于 2013-04-01T02:59:19.777 回答