简体   繁体   中英

Automatically sending emails in Magento

I'm helping someone set up a Magento shop which was bought from another company. The shop allows users to upload items and users can message each other on the site. It all works very nicely, except that a user doesn't receive an email notification when he receives a new message.

How would I go about implementing the sending of an automatic email each time a user receives a new message?

Thanks

You could add an event observer. You have code somewhere that takes care of the messages sent by the users. I'm sorry I cannot be more specific but it sounds like the site has a custom made module so I couldn't tell you where to look.

Once you find the function where the messaging magic happens, in there, you could dispatch your own event like so

Mage::dispatchEvent('user_message_sent_after');

Then, in the custom module, you look for the config.xml file (it should be in the etc/ folder). There you add something like

<frontend>
    <events>
        <user_message_sent_after>
            <observers>
                <your_name_for_this_tag>
                    <type>singleton</type>
                    <class>Packagename_Modulename_Model_Observer</class>
                    <method>sendEmailNotification</method>
                </your_name_for_this_tag>
            </observers>
        </user_message_sent_after>
    </events>
</frontend>

If there is an events tag already, you add to it rather than making a second one. 'user_message_sent_after' is not a default Magento event. I made up the name, you could use any other name, as long as it's equal to the name you used in your dispatchEvent call.

Define an email template. In the app\\locale\\yourlanguage_yourcountrycode\\template\\email\\ folder, add a file called message_notification

Hi {{var name}},<br>
{{var sender}} has sent you a message!<br>
Bye

Next, you finally add the actual observer. Find the model folder in your custom module and add a file called Observer.php. In this file you add something like

<?php
class Packagename_Modulename_Model_Observer {
  public function sendEmailNotification($observer) {
    // add emailing functionality
  }

Old but still very useful and basic explanation on how to send email is here: http://inchoo.net/ecommerce/magento/magento-custom-emails/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM