简体   繁体   English

在Magento中自动发送电子邮件

[英]Automatically sending emails in Magento

I'm helping someone set up a Magento shop which was bought from another company. 我正在帮助某人开设一家Magento商店,该商店是从另一家公司购买的。 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). 然后,在定制模块中,查找config.xml文件(该文件应该在etc /文件夹中)。 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. “ user_message_sent_after”不是默认的Magento事件。 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. 我组成了这个名称,您可以使用任何其他名称,只要它与您在dispatchEvent调用中使用的名称相等即可。

Define an email template. 定义一个电子邮件模板。 In the app\\locale\\yourlanguage_yourcountrycode\\template\\email\\ folder, add a file called message_notification 在app \\ locale \\ yourlanguage_yourcountrycode \\ template \\ email \\文件夹中,添加一个名为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. 在自定义模块中找到模型文件夹,然后添加一个名为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/ 有关如何发送电子邮件的旧的但仍然非常有用且基本的说明,请参见此处: http : //inchoo.net/ecommerce/magento/magento-custom-emails/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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