[英]Sending template emails in Magento
我正在创建一个Magento模块,该模块可用于在网站的某些情况下发送电子邮件。 我正在按照Branko Ajzele的教程进行操作,并且一切正常,直到尝试发送电子邮件时,从“发送”功能得到错误答复的地方。
下面是我正在使用的代码以及返回的结果:
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
事实是,尽管一切似乎进展顺利,但send函数返回的结果为false,当然我永远也不会收到电子邮件。 有没有像后端中的任何配置那样忘记做的事情?
----更新----
经过一番调查,我意识到我认为Magento安装中根本没有到达目的地的电子邮件,因此我认为应该从那里开始。
我已经在后端添加了所有电子邮件。 我检查了语言环境(语言)并将其更改为英语/美国(我读过可能是个问题)。 有什么建议吗?
您是否在localhost或实时站点上尝试它。 如果您在localhost中尝试,则需要在php.ini文件中更正电子邮件设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.