简体   繁体   English

在Magento中发送模板电子邮件

[英]Sending template emails in Magento

I'm creating a Magento Module that can be used to send emails in certain occasions of my website. 我正在创建一个Magento模块,该模块可用于在网站的某些情况下发送电子邮件。 I'm following the tutorial from Branko Ajzele and everything seems to work fine until I try to send the email where I get a false response from the Send function. 我正在按照Branko Ajzele的教程进行操作,并且一切正常,直到尝试发送电子邮件时,从“发送”功能得到错误答复的地方。

Below is the code I'm using along with the result returned: 下面是我正在使用的代码以及返回的结果:

public function sendAction() {

    /*
     * Loads the html file named 'custom_email_template1.html' from
     * app/locale/en_US/template/email/activecodeline_custom_email1.html
     */
    $emailTemplate  = Mage::getModel('core/email_template')
                            ->loadDefault('custom_email_template1');                                
//        var_dump(Mage::getModel('core/email_template'));
    //Create an array of variables to assign to template
    $emailTemplateVariables = array();
    $emailTemplateVariables['myvar1'] = 'Branko';
    $emailTemplateVariables['myvar2'] = 'Ajzele';
    $emailTemplateVariables['myvar3'] = 'ActiveCodeline';

    /**
     * The best part <img src="http://inchoo.net/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley">
     * Opens the activecodeline_custom_email1.html, throws in the variable array
     * and returns the 'parsed' content that you can use as body of email
     */

    /*
     * Or you can send the email directly,
     * note getProcessedTemplate is called inside send()
     */
    $emailTemplate->setSenderName('my name');
    $emailTemplate->setSenderEmail('example@domain.com');
    $emailTemplate->setTemplateSubject('STATUS CHANGED');

    var_dump($emailTemplate->send('example@domain.com'));
    echo "<br>";
    var_dump($emailTemplate);

    exit("test");

}

The var_dump given by var_dump($emailTemplate); 由var_dump($ emailTemplate)给出的var_dump; returns the object with all the information correctly as shown below: 正确返回具有所有信息的对象,如下所示:

bool(false)
object(Gp_Notify_Model_Email_Template)#82 (19) { ["_templateFilter:protected"]=> NULL ["_preprocessFlag:protected"]=> bool(false) ["_mail:protected"]=> NULL ["_designConfig:protected"]=> NULL ["_emulatedDesignConfig:protected"]=> bool(false) ["_initialEnvironmentInfo:protected"]=> NULL ["_eventPrefix:protected"]=> string(13) "core_abstract" ["_eventObject:protected"]=> string(6) "object" ["_resourceName:protected"]=> string(19) "core/email_template" ["_resource:protected"]=> NULL ["_resourceCollectionName:protected"]=> string(30) "core/email_template_collection" ["_cacheTag:protected"]=> bool(false) ["_dataSaveAllowed:protected"]=> bool(true) ["_isObjectNew:protected"]=> NULL ["_data:protected"]=> array(6) { ["template_type"]=> int(2) ["template_subject"]=> string(14) "STATUS CHANGED" ["template_text"]=> string(208) "
ActiveCodeline custom email example by Branko Ajzele

Hi there {{var myvar1}} {{var myvar2}} from {{var myvar3}}. This is just some example template to test custom email module.
" ["template_id"]=> string(22) "custom_email_template1" ["sender_name"]=> string(7) "my name" ["sender_email"]=> string(15) "phil@gproxy.com" } ["_hasDataChanges:protected"]=> bool(true) ["_origData:protected"]=> NULL ["_idFieldName:protected"]=> NULL ["_isDeleted:protected"]=> bool(false) } test

The thing is that although everything seems to go well the send function returns false and of course I never get to receive the email. 事实是,尽管一切似乎进展顺利,但send函数返回的结果为false,当然我永远也不会收到电子邮件。 Is there something I'm forgetting to do like any configuration in the backend or something? 有没有像后端中的任何配置那样忘记做的事情?

---- UPDATE ---- ----更新----

After some investigation I realized that there are no emails reaching their destination at all in my Magento installation which I thought they were, so figured I should start from there. 经过一番调查,我意识到我认为Magento安装中根本没有到达目的地的电子邮件,因此我认为应该从那里开始。

I have already added all the emails in the backend. 我已经在后端添加了所有电子邮件。 I checked the Locale (language) and changed it to english/US (which I read could be an issue). 我检查了语言环境(语言)并将其更改为英语/美国(我读过可能是个问题)。 Any advise? 有什么建议吗?

Are u trying it on the localhost or the live site. 您是否在localhost或实时站点上尝试它。 If you are trying in the localhost then you need to correct in the php.ini file for the email setting. 如果您在localhost中尝试,则需要在php.ini文件中更正电子邮件设置。

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

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