在 magento 中发送邮件 [英] sending mail in magento

查看:29
本文介绍了在 magento 中发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 magento 中发送电子邮件在索引控制器中编写操作?

我的索引控制器;

公共函数 postAction(){$post = $this->getRequest()->getPost();if(!$post) 退出;$translate = Mage::getSingleton('core/translate');$translate->setTranslateInline(false);尝试 {$postObject = new Varien_Object();$postObject->setData($post);if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {echo '<div class="error-msg">'.Mage::helper('contacts')->__('请输入有效的电子邮件地址.例如 johndoe@domain.com.').'

';出口;}$storeId = Mage::app()->getStore()->getStoreId();$emailId = Mage::getStoreConfig(self::XML_PATH_SAMPLE_EMAIL_TEMPLATE);$mailTemplate = Mage::getModel('core/email_template');$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$storeId))->setReplyTo($post['email'])->sendTransactional($templateId, $sender, $email, $name, $vars=array(), $storeId=null)if (!$mailTemplate->getSentSuccess()) {echo '<div class="error-msg">'.Mage::helper('contacts')->__('无法提交您的请求.请稍后再试.').'</div>';出口;}$translate->setTranslateInline(true);echo '<div class="success-msg">'.Mage::helper('contacts')->__('您的询问已提交,我们会尽快回复您.感谢您与我们联系.').'</div>';}捕获(异常 $e){$translate->setTranslateInline(true);echo '<div class="error-msg">'.Mage::helper('contacts')->__('无法提交您的请求.请稍后再试.').$e.'

';出口;}}

有什么不对吗..请帮我摆脱这个..提前致谢..

解决方案

您调用 sendTransactional() 的方式似乎存在一些问题.首先,$templateId 未定义,看起来您实际上已将模板 ID 存储在 $emailId 中.此外,$sender、$email 和 $name 未定义.你可以试试这样的:

->sendTransactional($emailId, 'general', $post['email'], "需要发送到这里的名字")

这仅在您从对 getStoreConfig() 的调用中获得有效模板 ID 时才有效.您还需要正确设置姓氏参数.

可能还有其他问题,但无论如何我一眼就注意到了这一点.

How to send email in magento writing an action in index controller?

my index controller;

public function postAction()
{           

    $post = $this->getRequest()->getPost();     
    if(!$post) exit;
    $translate = Mage::getSingleton('core/translate');
    $translate->setTranslateInline(false);
    try {
            $postObject = new Varien_Object();
            $postObject->setData($post);
            if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                echo '<div class="error-msg">'.Mage::helper('contacts')->__('Please enter a valid email address. For example johndoe@domain.com.').'</div>';
                exit; 
            }
            $storeId = Mage::app()->getStore()->getStoreId();
            $emailId = Mage::getStoreConfig(self::XML_PATH_SAMPLE_EMAIL_TEMPLATE);
            $mailTemplate = Mage::getModel('core/email_template');              
            $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$storeId))
                ->setReplyTo($post['email'])
                ->sendTransactional($templateId, $sender, $email, $name, $vars=array(), $storeId=null)

            if (!$mailTemplate->getSentSuccess()) {                 
                echo '<div class="error-msg">'.Mage::helper('contacts')->__('Unable to submit your request. Please, try again later.').'</div>';
                exit;
            }               
            $translate->setTranslateInline(true);
            echo '<div class="success-msg">'.Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.').'</div>';
            }   
            catch (Exception $e) {
            $translate->setTranslateInline(true);
            echo '<div class="error-msg">'.Mage::helper('contacts')->__('Unable to submit your request. Please, try again later.').$e.'</div>';
            exit;
        }       
}

is there any wrong.. please help me to out of this.. Thanks in advance..

解决方案

It looks like there are a few problems with the way you are calling sendTransactional(). First off, $templateId is not defined, it looks like you've actually stored the template id in $emailId. Also, $sender, $email, and $name are undefined. You can try something like this:

->sendTransactional($emailId, 'general', $post['email'], "Need a send to name here")

This is only going to work if you are getting a valid template id back from your call to getStoreConfig(). You'll also need to set the last name param correctly.

There could be other issues, but that's what I noticed with a quick glance anyway.

这篇关于在 magento 中发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆