【问题标题】:Sending template emails in Magento在 Magento 中发送模板电子邮件
【发布时间】:2011-08-31 16:04:34
【问题描述】:

我正在创建一个 Magento 模块,可用于在我的网站的某些场合发送电子邮件。我正在按照 Branko Ajzele 的教程进行操作,一切似乎都正常,直到我尝试发送电子邮件时收到来自 Send 函数的错误响应。

下面是我正在使用的代码以及返回的结果:

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");

}

var_dump($emailTemplate); 给出的 var_dump正确返回包含所有信息的对象,如下所示:

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

问题是,尽管一切似乎都很顺利,但发送函数返回 false,当然我从来没有收到过电子邮件。 有什么我忘记做的事情,比如后端的任何配置吗?

---- 更新----

经过一番调查,我意识到在我的 Magento 安装中根本没有电子邮件到达目的地,我认为它们是,所以我想我应该从那里开始。

我已经在后端添加了所有的电子邮件。 我检查了语言环境(语言)并将其更改为英语/美国(我读到的可能是一个问题)。 有什么建议吗?

【问题讨论】:

  • 你安装的 Gp_Notify 模块是什么?它正在替换标准的电子邮件模板对象,可能是个问题。

标签: email templates magento


【解决方案1】:

你是在本地主机还是现场站点上尝试它。如果您在 localhost 中尝试,则需要在 php.ini 文件中更正电子邮件设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多