用magento发送邮件

时间:2014-02-17 17:55:28

标签: php magento-1.8

当我点击提交时,我无法发送magento邮件给出错误(无效的交易电子邮件代码)

这是indexContoller.php中的post action方法:

public function postAction()
    {
        $test = "";
        $post = $this->getRequest()->getPost();
        if ( $post ) {
            $translate = Mage::getSingleton('core/translate');
          // @var $translate Mage_Core_Model_Translate 
            $translate->setTranslateInline(false);
            try {
                $postObject = new Varien_Object();
                $postObject->setData($post);

                $error = false;

                if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
                    $error = true;
                    $test .= "name - ";
                }

                if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {
                    $error = true;
                    $test .= "comment - ";
                }

                if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                    $error = true;
                    $test .= "email - ";
                }

                if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
                    $error = true;
                    $test .= "hideit - ";
                }

                if ($error) {
                    throw new Exception();
                }
                 $mailTemplate = Mage::getModel('core/email_template');
               //  @var $mailTemplate Mage_Core_Model_Email_Template 
                $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                    ->setReplyTo($post['email'])
                    ->sendTransactional(
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                        null,
                        array('data' => $postObject)
                    );

                if (!$mailTemplate->getSentSuccess()) {
                    throw new Exception();
                }
                    Mage::getSingleton('customer/session')->addSuccess(Mage::helper('mymodule')->__' Your request was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
                    $this->_redirect('*/*/');


                return;
            } catch (Exception $e) {
                $translate->setTranslateInline(true);

                Mage::getSingleton('customer/session')->addError(Mage::helper('mymodule')->__($test." || ".$e->getMessage()." || ".$e->getFile()." || ".$e->getLine()));
                $this->_redirect('*/*/');
                return;
            }

        } else {
            $this->_redirect('*/*/');
        }
    }

这是config.xml中的模板:

<global>
<template>
            <email>
                <mymodule_email_email_template translate="label" module="mymodule">
                    <label>mymodule Form</label>
                    <file>form.html</file>
                    <type>text</type>
                </extendedcontacts_email_email_template>
            </email>
        </template>
     </global>

这个问题有什么解决方案吗? 代码中有错误吗?

0 个答案:

没有答案
相关问题