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

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

问题描述

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

How to send email in magento writing an action in 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..

推荐答案

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

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

仅当从对getStoreConfig()的调用中获得有效的模板ID时,此方法才起作用.您还需要正确设置姓氏参数.

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天全站免登陆