1

This question already has an answer here:

I managed to add the 2nd emails select field but am wondering how to send 2 different emails to the newsletter subscriber.

enter image description here

marked as duplicate by Jonathan Hussey, Marius, Anna Völkl, Amasty, Keyul Shah Sep 12 '14 at 11:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Out of the box Magento will only send one subscription success email. That said you can always include your voucher in the transactional email. To send a second email will require additional modifications. – Eirik Sep 11 '14 at 5:08
  • Hi Eirik, thanks for your reply. Do you know how to customize the additional email? – chris_magento Sep 11 '14 at 7:56
  • 1
    you have now duplicated your original question 4 times, please avoid doing this, people will answer your question if they have an answer, spamming the forums with the same question multiple time is not the way to do it. – Jonathan Hussey Sep 12 '14 at 5:42
0

Currently Magento allows to send only one success email template by default. We can set this success email template via

System  >  Configuration  > Newsletter  >  Success Email Template

You can see that, it uses a dropdown section. This allows us to set only one email template for success mail. So you need to change this section to multiselct, so that you can select multiple success email templates. You again need to rewrite Mage_Newsletter's Subscriber model class in order to send multiple mails at a time.

So let us create a custom module, that do this for us. I love to call this module as Rkt_TwoNlSuccess.

Activation file of the module

File : app\etc\modules\Rkt_TwoNlSuccess.xml

<config>
    <modules>
        <Rkt_TwoNlSuccess>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Newsletter />
            </depends>
        </Rkt_TwoNlSuccess>
    </modules>
</config>

Note our module depends upon Mage_Newletter module. It is necessary.

System.xml file

This file defines system configuration definitions and alternation. We use this file to make success email template field multiselect instead of select.

File : app\code\local\Rkt\TwoNlSuccess\etc\system.xml

<config>
    <sections>
        <newsletter>
            <groups>
                <subscription>
                    <fields>
                        <success_email_template>
                            <label>Success Email Template</label>
                            <frontend_type>multiselect</frontend_type>
                            <source_model>adminhtml/system_config_source_email_template</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </success_email_template>
                    </fields>
                </subscription>
            </groups>
        </newsletter>
    </sections>
</config>

Note we changed front type.

<frontend_type>multiselect</frontend_type>

So our first part is over. Now its time to do model rewrite

Rewrite Model file

We need to rewrite sendConfirmationSuccessEmail() method that is defined in the model class Mage_Newsletter_Model_Subscriber. This is important since the default code allows us to send only one mail. In order to do that you need to define two files.

File : app\code\local\Rkt\TwoNlSuccess\etc\config.xml

<config>
    <modules>
        <Rkt_Freepro>
            <version>1.0.0</version>
        </Rkt_Freepro>
    </modules>
    <global>
        <models>
            <newsletter>
                <rewrite>
                    <subscriber>Rkt_TwoNlSuccess_Model_Subscriber</subscriber>
                </rewrite>
            </newsletter>
        </models>
    </global>
</config>

This file just tells magento that, I need to rewrite the class Mage_Newsletter_Model_Subscriber with my custom class Rkt_TwoNlsuccess_Model_Subscriber. So magento will process this custom model class instead of default one. This is the great flexibility that Magento offers.

File : app\code\local\Rkt\TwoNlSuccess\Model\Subscriber.php

<?php
class Rkt_TwoNlSuccess_Model_Subscriber extends Mage_Newsletter_Model_Subscriber
{
    const XML_PATH_SUCCESS_EMAIL_TEMPLATE       = 'newsletter/subscription/success_email_template';
    const XML_PATH_SUCCESS_EMAIL_IDENTITY       = 'newsletter/subscription/success_email_identity';

    public function sendConfirmationSuccessEmail()
    {
        if ($this->getImportMode()) {
            return $this;
        }

        if(!Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE)
           || !Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY)
        ) {
            return $this;
        }

        $translate = Mage::getSingleton('core/translate');
        /* @var $translate Mage_Core_Model_Translate */
        $translate->setTranslateInline(false);

        $email = Mage::getModel('core/email_template');

        $email_templates = explode(',', Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE));
        $identity = Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY);

        foreach ($email_templates as $template) {
            $email->sendTransactional(
                $template,
                $identity,
                $this->getEmail(),
                $this->getName(),
                array('subscriber'=>$this)
            );
        }


        $translate->setTranslateInline(true);

        return $this;
    }

}

Here we are rewriting the method sendConfirmationSuccessEmail(). The following code that does the trick here

        $email_templates = Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_TEMPLATE);
        $identity = Mage::getStoreConfig(self::XML_PATH_SUCCESS_EMAIL_IDENTITY);

        foreach ($email_templates as $template) {
            $email->sendTransactional(
                $template,
                $identity,
                $this->getEmail(),
                $this->getName(),
                array('subscriber'=>$this)
            );
        }

This code allows you to send any number of emails. So now you can send more than two success emails if you desire.

EDIT

You set need confirm to YES. That is what actually making problem here. If that values is set, then Magento will send success mails to only logged in customers who are trying to subscribe newsletter. For guest users, it will always send confirm mail.

In order to send success mail for all users, you need to set need confirm to NO.

Please note, there is a minor bug in my subscriber.php file. I have fixed it and tested it. It works in local server. I have updated that code here. So save this updated code inside app/code/local/Rkt/TwoNlSuccess/Model/Subscriber.php.

Let me know whether it solves your problem.

Hope that will help

  • the multiselect doesn't work..hmmm – chris_magento Sep 15 '14 at 3:53
  • @chris_magento : didn't get you. what is the problem that you facing ? – Rajeev K Tomy Sep 15 '14 at 4:08
  • I am getting this error when I click on the verification link in the email dev1.jeoeljewelry.com/2ndsuccessemail1.jpg. Any ideas? – chris_magento Sep 15 '14 at 4:18
  • this is not what my code does. My code allow you to add multiple success email template at a time instead of adding an extra field in newsletter configuration section – Rajeev K Tomy Sep 15 '14 at 4:30
  • Sorry for the confusion. Initially I set as multiselect but it doesn't work so i change it to select...Have a look dev1.jeoeljewelry.com/multiselect.jpg Appreciate your help ... – chris_magento Sep 15 '14 at 4:35
0

Welcome to Magento.SE!

This is actually an option by default in Magento configuration! Go to System > Configuration > Sales > Sales Emails

enter image description here

Enter a secondary address to CC/BCC

  • 1
    Misunderstood the reasoning for the question but will leave this here so others don't misunderstand, too. Feel free to downvote! – philwinkle Sep 11 '14 at 5:18
  • he he. I love it. you rocks @philwinkle :) – Rajeev K Tomy Sep 11 '14 at 5:41
  • 1
    have a look on my answer. He posted the same question 4 times here. So I decided to "react". That is what this answer. NOte: I am not critisizing him. I can understand his feeling :) – Rajeev K Tomy Sep 12 '14 at 5:58

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