当我单击提交时,我无法在 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>
这个问题有什么解决办法吗?代码中有错误吗?