--- /var/www/app/code/core/Mage/Contacts/controllers/IndexController.php.org 2013-11-11 17:44:06.000000000 +0100 +++ /var/www/app/code/core/Mage/Contacts/controllers/IndexController.php 2013-11-13 11:34:56.000000000 +0100 @@ -91,7 +91,40 @@ if ($error) { throw new Exception(); } + + $fileName = ''; + if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') { + try { + $fileName = $_FILES['attachment']['name']; + $fileExt = strtolower(substr(strrchr($fileName, "."), 1)); + $fileNamewoe = rtrim($fileName, $fileExt); + $fileName = preg_replace('/\s+', '', $fileNamewoe) . time() . '.' . $fileExt; + + $uploader = new Varien_File_Uploader('attachment'); + $uploader->setAllowedExtensions(array('jpg', 'png', 'bmp', 'gif', 'pdf', 'zip', 'rar')); + $uploader->setAllowRenameFiles(false); + $uploader->setFilesDispersion(false); + $path = Mage::getBaseDir('media') . DS . 'contacts'; + if(!is_dir($path)){ + mkdir($path, 0777, true); + } + $uploader->save($path . DS, $fileName); + + } catch (Exception $e) { + $error = true; + } + } + $mailTemplate = Mage::getModel('core/email_template'); + if($fileName != '') { + $attachmentFilePath = Mage::getBaseDir('media'). DS . 'contacts' . DS . $fileName; + if(file_exists($attachmentFilePath)){ + $fileContents = file_get_contents($attachmentFilePath); + $attachment = $mailTemplate->getMail()->createAttachment($fileContents); + $attachment->filename = $fileName; + } + } + /* @var $mailTemplate Mage_Core_Model_Email_Template */ $mailTemplate->setDesignConfig(array('area' => 'frontend')) ->setReplyTo($post['email'])