簡體   English   中英

如何在magento中為簡訊訂閱創建管理員通知郵件

[英]how to create admin notification mail for newsletter subscription in magento

我正在嘗試為magento 1.7創建一個模塊,每當新用戶訂閱新聞通訊時,該模塊就會向管理員發送通知郵件。 到目前為止,我已經成功發送了郵件。 但是,我的代碼沒有將getEmail和getId值顯示在發送給管理員的郵件中。 如果有人可以闡明我要去的地方,那將很棒。 這是代碼:

應用程序/代碼/本地/通知/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>

應用程序/代碼/本地/通知/ Biju /模型/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');

            }

        }

}

app / 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>

您有錯字:

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

您的“訂戶”拼寫錯誤為“訂戶”

要在觀察者中獲取訂戶電子郵件值和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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM