0

Is it possible I add my email as Bcc to get email any time someone successfully subscribe for newsletter in Magento?

This is really important for us to be notified any time someone subscribe for newsletter.

Observer.php

<?php

class Mydons_Newsletteralert_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'] = 'ghorbanisaghi@yahoo.com';
        try{
            $emailtemplate->sendTransactional(
                self::XML_PATH_EMAIL_TEMPLATE,
                $sender,
                'saghi.ghorbani@tricorsenedi.com',
                'admin',
                array('subscriber' => $subscriber)
            );
        }
        catch(Mage_Core_Exception $e){
            echo $e->getMessage();
            Mage::log($e->getMessage(), null, 'newsletter.log');
        }
    }
}

config.xml

<config>
    <modules>
        <Mydons_Newsletteralert>
            <version>0.1.0</version>
        </Mydons_Newsletteralert>
    </modules>
    <global>
        <models>
            <Mydons_Newsletteralert>
                <class>Mydons_Newsletteralert_Model</class>
            </Mydons_Newsletteralert>
        </models>
        <template>
            <email>
                <newsletter_alert_template template="label" module="mydons">
                    <label>Newsletter Alert to Admin</label>
                    <file>newsletter_bcc_email.html</file>
                    <type>html</type>
                </newsletter_alert_template>
            </email>
        </template>
    </global>
    <frontend>
        <events>
            <newsletter_subscriber_save_after>
                <observers>
                    <Mydons_Newsletteralert_Model_Observer>
                        <type>singleton</type>
                        <class>Mydons_Newsletteralert_Model_Observer</class>
                        <method>newsletteralert</method>
                    </Mydons_Newsletteralert_Model_Observer>
                </observers>
            </newsletter_subscriber_save_after>
        </events>
    </frontend>
</config>
0

Go through this link here

Good luck...

  • Hi Thanks for your answer the tutorial is amazing, But I still have problem! I followed the tutorial exactly but still don't get the email after subscription! Do you want me to put my code in question maybe you can take a look at it and help me out :( Thanks – user3330766 Jun 2 '15 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.