/** * * @param string $from Sender, left null to use system setting. * @param string/array $to To, format as 'Firstname Lastname' <*****@*****.**> or email address only. * @param string/array $cc CC, format as 'Firstname Lastname' <*****@*****.**> or email address only. * @param string $subject String message subject. * @param string $message Message body, html or plain text. * @param boolean $html True for html body, false for plain. * @return boolean True/False depending is the operation was completed. */ public function Send($to = array(), $subject, $message, $html = true, $from = null, $cc = array()) { if ($html == true) { $theme = SystemSetting::getByKey("ARC_THEME"); if (file_exists(system\Helper::arcGetPath(true) . "themes/" . $theme->value . "/email.php")) { $content = file_get_contents(system\Helper::arcGetPath(true) . "themes/" . $theme->value . "/email.php"); $message = system\Helper::arcParseEmail($content, $message); } } Log::createLog("info", "arcmail", "Send email request, mode: " . $this->mode); // Set from details if ($from == null) { $from = $this->data["sender"]; } // Build to list if (!is_array($to)) { $list = array(); $list[] = $to; $to = $list; } // Build to list if (!is_array($cc)) { $list = array(); $list[] = $cc; $cc = $list; } // Build Mail Header $headers = "MIME-Version: 1.0\r\n"; if ($html == true) { // Html content $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n"; } else { // Plain test $headers .= "Content-Type: text/plain;\r\n"; } Log::createLog("info", "arcmail", "Mail headers built"); switch ($this->mode) { case "MAIL": // Add from header $headers .= "From: " . $from . "\r\n"; // Build recipients list $toList = ""; foreach ($to as $recipient) { $toList .= $recipient . ", "; } $toList = substr($toList, 0, -2); Log::createLog("success", "arcmail", "PHP mail created."); // Send mail mail($toList, $subject, $message, $headers); Log::createLog("success", "arcmail", "PHP mail sent."); break; case "SMTP": include system\Helper::arcGetPath(true) . "app/classes/PHPMailer/PHPMailerAutoload.php"; $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = $this->data["server"]; if (empty($this->data["username"]) && empty($this->data["password"])) { $mail->SMTPAuth = false; } else { $mail->SMTPAuth = true; $mail->Username = $this->data["username"]; $smtp_password = system\Helper::arcDecrypt($this->data["password"]); $mail->Password = $smtp_password; } $mail->setFrom($from); foreach ($to as $email) { $mail->addAddress($email); } foreach ($cc as $email) { $mail->addCC($email); } $mail->isHTML($html); $mail->Subject = $subject; $mail->Body = $message; if (!$mail->send()) { Log::createLog("danger", "arcmail", "SMTP: " . $mail->ErrorInfo); } else { Log::createLog("success", "arcmail", "SMTP: Message sent"); } break; } }