From 421ea9456f23d1c213008bf8badb60ac9c07eeb4 Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Thu, 19 Apr 2012 13:00:41 +0000 Subject: [PATCH] [-] Project : #PSFV-816 - Allow to attach multiple files to an email with the function Mail::send --- classes/Mail.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/classes/Mail.php b/classes/Mail.php index 861d62e04..2ed93e6be 100644 --- a/classes/Mail.php +++ b/classes/Mail.php @@ -36,6 +36,22 @@ class MailCore const TYPE_TEXT = 2; const TYPE_BOTH = 3; + /** + * Send Email + * + * @param int $id_lang Language of the email (to translate the template) + * @param string $template Template + * @param string $subject + * @param string $templateVars + * @param string $to + * @param string $toName + * @param string $from + * @param string $fromName + * @param array $fileAttachment Array with three parameters (content, mime and name). You can use an array of array to attach multiple files + * @param bool $modeSMTP + * @param string $templatePath + * @param bool $die + */ public static function Send($id_lang, $template, $subject, $templateVars, $to, $toName = null, $from = null, $fromName = null, $fileAttachment = null, $modeSMTP = null, $templatePath = _PS_MAIL_DIR_, $die = false) { @@ -203,8 +219,17 @@ class MailCore $message->attach(new Swift_Message_Part($templateTxt, 'text/plain', '8bit', 'utf-8')); if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML) $message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8')); - if ($fileAttachment && isset($fileAttachment['content']) && isset($fileAttachment['name']) && isset($fileAttachment['mime'])) - $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime'])); + if ($fileAttachment && !empty($fileAttachment)) + { + // Multiple attachments? + if (!is_array(current($fileAttachment))) + $fileAttachment = array($fileAttachment); + + foreach ($fileAttachment as $attachment) + if (isset($attachment['content']) && isset($attachment['name']) && isset($attachment['mime'])) + $message->attach(new Swift_Message_Attachment($attachment['content'], $attachment['name'], $attachment['mime'])); + } + /* Send mail */ $send = $swift->send($message, $to, new Swift_Address($from, $fromName)); $swift->disconnect();