We have two newsletter tools in use (don't ask me why). The "old" one and the default one from Magento. For the old one to receive subscribers, we want to send an email with the address of the subscriber to a specified email address.
Hence, I need this:
When the user is subscribing and his data is added to Magento, it should als trigger an email to that specified email address (hardcoded, we will remove it later).
Where in the code can I achieve this, so that it covers all possible subscriptions (directly from page, when registering etc.)?
Best Answer
Currently Magento allows to send only one success email template by default. We can set this success email template via
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
'sSubscriber
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
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
Note we changed front 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 classMage_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
This file just tells magento that, I need to rewrite the class
Mage_Newsletter_Model_Subscriber
with my custom classRkt_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
Here we are rewriting the method
sendConfirmationSuccessEmail()
. The following code that does the trick hereThis code allows you to send any number of emails. So now you can send more than two success emails if you desire.
**side note :**Under
System > Configuration > Newsletter > Allow guest Customers
, If that values is set toYes
, 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
toNO
.Hope that will help
[This answer is a part of #mageStackDay. It is an event conducted by Magento Community members as part of increasing the question-answer ratio. For more information http://www.magestackday.com/]