Browse Source

Fix attached files in mail - Refs # 8154

José Loguercio 9 years ago
parent
commit
97e9aacf0f
3 changed files with 29 additions and 5 deletions
  1. 17 2
      main/inc/lib/api.lib.php
  2. 8 1
      main/inc/lib/message.lib.php
  3. 4 2
      main/inc/lib/notification.lib.php

+ 17 - 2
main/inc/lib/api.lib.php

@@ -7845,8 +7845,8 @@ function api_create_protected_dir($name, $parentDirectory)
  * @param string    sender e-mail
  * @param array     extra headers in form $headers = array($name => $value) to allow parsing
  * @param array     data file (path and filename)
- * @param array     data to attach a file (optional)
  * @param bool      True for attaching a embedded file inside content html (optional)
+ * @param array     Additional parameters
  * @return          returns true if mail was sent
  * @see             class.phpmailer.php
  */
@@ -7967,7 +7967,22 @@ function api_mail_html(
 
     // Attachment ...
     if (!empty($data_file)) {
-        $mail->AddAttachment($data_file['path'], $data_file['filename']);
+        $o = 0;
+        foreach ($data_file as $file_attach) {
+            if (!empty($file_attach['path']) && !empty($file_attach['filename'])) {
+                $mail->AddAttachment($file_attach['path'], $file_attach['filename']);
+            }
+            $o++;
+        }
+    } elseif (is_array($_FILES)) {
+        $data_file = $_FILES;
+        $o = 0;
+        foreach ($data_file as $file_attach) {
+            if (!empty($file_attach['tmp_name']) && !empty($file_attach['name'])) {
+                $mail->AddAttachment($file_attach['tmp_name'], $file_attach['name']);
+            }
+            $o++;
+        }
     }
 
     // Only valid addresses are accepted.

+ 8 - 1
main/inc/lib/message.lib.php

@@ -362,6 +362,12 @@ class MessageManager
             // Load user settings.
             $notification = new Notification();
             $sender_info = api_get_user_info($user_sender_id);
+            
+            // add file attachment additional attributes
+            foreach ($file_attachments as $index => $file_attach) {
+                $file_attachments[$index]['path'] = $file_attach['tmp_name'];
+                $file_attachments[$index]['filename'] = $file_attach['name'];
+            }
 
             if (empty($group_id)) {
                 $type = Notification::NOTIFICATION_TYPE_MESSAGE;
@@ -373,7 +379,8 @@ class MessageManager
                     array($receiver_user_id),
                     $subject,
                     $content,
-                    $sender_info
+                    $sender_info,
+                    $file_attachments
                 );
             } else {
                 $usergroup = new UserGroup();

+ 4 - 2
main/inc/lib/notification.lib.php

@@ -227,7 +227,8 @@ class Notification extends Model
         $user_list,
         $title,
         $content,
-        $senderInfo = array()
+        $senderInfo = array(),
+        $attachments = array()
     ) {
         $this->type = intval($type);
         $content = $this->formatContent($content, $senderInfo);
@@ -307,7 +308,8 @@ class Notification extends Model
                                 Security::filter_terms($content),
                                 $this->adminName,
                                 $this->adminEmail,
-                                $extraHeaders
+                                $extraHeaders,
+                                $attachments
                             );
                         }
                         $sendDate = api_get_utc_datetime();