--- G:\D7-modules\contact_attach\contact_attach.module
+++ G:\D7-modules\contact_attach - test\contact_attach.module
@@ -99,7 +99,7 @@
     );
     $form['attachments_allowed'] = array(
       '#type' => 'value',
-      '#value' => _contact_attach_return_max_attachments($roles, $contact_attach_numbers),
+      '#value' => _contact_attach_return_max_attachments($roles, $contact_attach_numbers, $contact_form_short, $form),
     );
     $form['allowed_extensions'] = array(
       '#type' => 'value',
@@ -113,7 +113,7 @@
     $description = t('Files must be less than !size.', array('!size' => '<strong>' . format_size($form['file_size_limit']['#value']) . '</strong>'));
     $description .= '<br />' . t('Allowed file types: !extensions.', array('!extensions' => '<strong>' . $form['allowed_extensions']['#value'] . '</strong>'));
 
-    if ($form['attachments_allowed']['#value'] !== 1) {
+    if ($form['attachments_allowed']['#value'] > 1) {
       $form['attachments'] = array(
         '#type' => 'fieldset',
         '#title' => t('Attachments'),
@@ -172,6 +172,7 @@
   );
 
   // Loop through each possible attachment.
+  if (!empty($_FILES)) {
   foreach ($_FILES['files']['name'] as $temp_name => $file_name) {
     $file = file_save_upload($temp_name, $validators);
     if ($file === FALSE) {
@@ -179,6 +180,7 @@
     }
   }
 }
+}
 
 /**
  * Form submission handler for contact_site_form().
@@ -324,6 +326,7 @@
 function _contact_attach_process_attachments($message) {
   $return_message = array();
 
+  $files = array();
   if ($message['params']['file_field_type'] === 'managed_file') {
     // Loop through each possible attachment when using managed_file fields.
     for ($i = 1; $i <= $message['params']['attachments_allowed']; $i++) {
@@ -333,7 +336,7 @@
       }
     }
   }
-  else {
+  elseif (!empty($_FILES)) {
     // Loop through each possible attachment when using simple file fields.
     foreach ($_FILES['files']['name'] as $temp_name => $file_name) {
       if ($file = file_save_upload($temp_name)) {
@@ -466,7 +469,8 @@
 }
 
 /**
- * Returns maximum number of attachments allowed based on all supplied roles.
+ * Returns maximum number of attachments allowed based on all supplied roles
+ * when contact is allowed to receive attachments.
  *
  * @param array $roles
  *   An associative array of the active user's valid roles.
@@ -477,7 +481,7 @@
  * @return int
  *   The maximum number of attachments allowed based on all supplied roles.
  */
-function _contact_attach_return_max_attachments($roles, $contact_attach_numbers) {
+function _contact_attach_return_max_attachments($roles, $contact_attach_numbers, $contact_form_short, $form) {
   $attachments_allowed = 1;
 
   foreach ($roles as $rid) {
@@ -487,6 +491,33 @@
     }
   }
 
+  if (module_exists('contact_forms')) {
+    if ($contact_form_short == 'site' && $attachments_allowed && !variable_get('contact_attach_all', 1)) {
+      if (!empty($form['#action'])) {
+        $contacts = variable_get('contact_attach_contacts', array());
+        if (!empty($contacts)) {
+          $allowed = 0;
+          $parts = explode('/', strtolower($form['#action']));
+          $partnr = count($parts) - 1;
+          foreach ($parts AS $key => $part) {
+            if ($part == 'contact') {
+              $partnr = $key + 1;
+            }
+          }
+          $searchkey = str_replace(array('-','_') , ' ' , $parts[$partnr]);
+          foreach ($form['cid']['#options'] AS $key => $value) {
+            if (!strcasecmp($searchkey, $value)) {
+              if (array_key_exists($key, $contacts)) {
+                $allowed = $attachments_allowed;
+              }
+            }
+          }
+          $attachments_allowed = $allowed;
+        }
+      }
+    }
+  }
+
   return $attachments_allowed;
 }
 