2015-05-29 132 views
1

我想創建一個允許客戶附加文件的magento模塊聯繫頁面。我遵循magephsycho這個教程,並創建了自己的模塊,但是我收到空白的電子郵件。在google上搜索時,我發現這個stackexchange question並修改了IndexController.php。我現在收到帶有內容但沒有附件的電子郵件。magento聯繫電子郵件附件,沒有收到附件

我是新來的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保存在應用程序/代碼/本地/附件/ Eattachment /等

<?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 /本地/附件/ Eattachment /控制器

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保存在應用的/ etc /模塊

<?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}} 

我希望我給有用信息的代碼。截至目前我不知道發生了什麼事。我不確定是否將文件保存在適當的位置。

我的問題是我沒有收到聯繫我們頁面發送的任何電子郵件附件。

謝謝!

回答

0

我發表了這個問題已經有一個月了。同時,在我解決這個問題之前,我轉到了項目的其他階段。

我發現從我安裝的聯繫我們擴展的問題。

爲了解決這個問題,我卸載了該擴展和修改我的代碼

變型:

  1. 無需包括異動電子郵件頁面中輸入字段。這是修改後的代碼。

    名稱:{{VAR data.name}} 電子郵件:{{VAR data.email}} 電話:{{VAR data.telephone}} PollQuestions:{{VAR data.pollquestions}} OtherSpecify: {{var data.othersSpecify}} 評論:{{var data。註釋}}

  2. 我更換控制器代碼從上方到該

    如果(file_exists($ attachmentFilePath)){$ = fileContents的file_get_contents($ attachmentFilePath);

       $attachment = $mailTemplate->getMail()->createAttachment($fileContents); 
    
           $attachment->filename = $fileName; 
          } 
    

代碼工作,現在我可以接收電子郵件附件。

希望這可以幫助別人。