/** * Send an email with a list of attachments * * @param mixed $toEmail * @param mixed $subject * @param mixed $message * @param mixed $fromEmail * @param mixed $attachments */ public static function sendEmailWithAttachments($toEmail, $subject, $message, $fromEmail = false, $attachments = array(), $ccEmail = false) { // We allow mutiple emails $emails = explode(',', $toEmail); $ccEmails = ""; if (!empty($ccEmail)) { $ccEmails = explode(',', $ccEmail); } if (empty($emails)) { return false; } // Email with template $emailBody = $message ? $message : ''; $emailSubject = $subject ? $subject : ''; $emailAgent = new Mail_Mail('simple_text', $fromEmail ? false : true); $emailAgent->setBody($emailBody)->setSubject($emailSubject); if ($fromEmail) { $fromName = $fromEmail; $userObj = Repo_User::getInstance(); $user_id = $userObj->emailExists($fromEmail); $_user = new Object_User($user_id); if (!$_user->getId()) { continue; } $userInfoArr = $_user->getBasicInfo(); if (!empty($userInfoArr["firstname"]) || !empty($userInfoArr["surname"])) { $fromName = trim($userInfoArr["firstname"] . " " . $userInfoArr["surname"]); } $emailAgent->setFrom($fromName, $fromEmail); } if (!empty($attachments)) { foreach ($attachments as $_a) { // Add attachment $emailAgent->addAttachment($_a['path'], $_a['name']); } } if (!empty($ccEmail)) { foreach ($ccEmails as $_ccEmail) { $emailAgent->setCc($_ccEmail, $_ccEmail); } } foreach ($emails as $_toEmail) { $emailAgent->setTo($_toEmail); } try { $emailAgent->send(); } catch (Exception $e) { // Ignore for now } return true; }