我正在尝试创建一个magento模块联系页面,允许客户附加文件。我遵循magephsycho的这个教程,并创建了我自己的模块,但我收到空白的电子邮件。在谷歌搜索我发现这个stackexchange问题和修改IndexController.php。我现在收到有内容但没有附件的电子邮件。
我是新来的magento,我不知道哪里出错了。
这是我的HTML代码:<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post" enctype="multipart/form-data">
<input name="MAX_FILE_SIZE" type="hidden" value="2000000" />
<input name="fileattachment" id="fileattachment" title="<?php echo Mage::helper('contacts')->__('FileAttachment') ?>" placeholder="<?php echo Mage::helper('contacts')->__('Upload File') ?>" value="fileattachment" class="input-text" type="file" />
这是我的config.xml保存在app/code/local/Attachment/Eattachment/etc
<?xml version="1.0"?>
<config>
<frontend>
<routers>
<contacts>
<args>
<modules>
<Attachment_Eattachment before="Mage_Contacts">Attachment_Eattachment</Attachment_Eattachment>
</modules>
</args>
</contacts>
</routers>
</frontend>
</config>
这是我在IndexController.php中替换的代码,该代码保存在app/code/local/Attachment/Eattachment/controllers
if(file_exists($attachmentFilePath)){
mailTemplate->getMail()->createAttachment(
file_get_contents($attachmentFilePath),
Zend_Mime::TYPE_OCTETSTREAM,
Zend_Mime::DISPOSITION_ATTACHMENT,
Zend_Mime::ENCODING_BASE64,
$fileName
);
}
最后,这是config.xml,它将模块介绍给magento保存在app/etc/modules
<?xml version="1.0"?>
<config>
<modules>
<Attachment_Eattachment>
<active>true</active>
<codePool>local</codePool>
</Attachment_Eattachment>
</modules>
</config>
更新:这是来自管理事务电子邮件的代码
Name: {{var data.name}}
Email: {{var data.email}}
Telephone: {{var data.telephone}}
PollQuestions: {{var data.pollquestions}}
OtherSpecify: {{var data.othersSpecify}}
FileAttachment: {{var data.fileattachment}}
Comment: {{var data.comment}}
我希望我提供了有用的信息。到现在为止,我还不知道发生了什么。我不确定我是否把文件保存在正确的位置。
我的问题是我没有收到任何电子邮件附件发送的联系我们页面。
谢谢!
我发这个问题已经一个月了。在解决这个问题之前,我要先进入项目的其他阶段。
我从我安装的"联系我们"扩展中发现了问题。
为了解决这个问题,我卸载了扩展并修改了我的代码 修改:
不需要在Transactional Email页面中包含输入字段。这是修改后的代码
名称:{{var data.name}}Email: {{var data.email}}电话:{{var data.telephone}}PollQuestions: {{var data.pollquestions}}OtherSpecify: {{var data.othersSpecify}}注释:{{var data.comment}}
我将上面的控制器代码替换为这个
如果(file_exists (attachmentFilePath美元)){$fileContents = file_get_contents($attachmentFilePath);
$attachment = $mailTemplate->getMail()->createAttachment($fileContents); $attachment->filename = $fileName; }
代码工作,我现在可以接收电子邮件附件。
希望对大家有所帮助