function runner_mail($params)
{
    $customSMTP = "0";
    if ($customSMTP == "1") {
        include_once getabspath('libs/phpmailer/class.phpmailer.php');
        include_once getabspath('libs/phpmailer/class.smtp.php');
        return runner_mail_smtp($params);
    }
    $from = isset($params['from']) ? $params['from'] : "";
    if (!$from) {
        $from = "";
    }
    $to = isset($params['to']) ? $params['to'] : "";
    $body = isset($params['body']) ? $params['body'] : "";
    $cc = isset($params['cc']) ? $params['cc'] : "";
    $bcc = isset($params['bcc']) ? $params['bcc'] : "";
    $replyTo = isset($params['replyTo']) ? $params['replyTo'] : "";
    $priority = isset($params['priority']) ? $params['priority'] : "";
    $charset = "";
    $isHtml = false;
    if (!$body) {
        $body = isset($params['htmlbody']) ? $params['htmlbody'] : "";
        $charset = isset($params['charset']) ? $params['charset'] : "";
        if (!$charset) {
            $charset = "utf-8";
        }
        $isHtml = true;
    }
    $subject = $params['subject'];
    //
    $header = "";
    if ($isHtml) {
        $header .= "MIME-Version: 1.0\r\n";
        $header .= 'Content-Type: text/html;' . ($charset ? ' charset=' . $charset . ';' : '') . "\r\n";
    }
    if ($from) {
        if (strpos($from, '<') !== false) {
            $header .= 'From: ' . $from . "\r\n";
        } else {
            $header .= 'From: <' . $from . ">\r\n";
        }
        @ini_set("sendmail_from", $from);
    }
    if ($cc) {
        $header .= 'Cc: ' . $cc . "\r\n";
    }
    if ($bcc) {
        $header .= 'Bcc: ' . $bcc . "\r\n";
    }
    if ($priority) {
        $header .= 'X-Priority: ' . $priority . "\r\n";
    }
    if ($replyTo) {
        if (strpos($replyTo, '<') !== false) {
            $header .= 'Reply-to: ' . $replyTo . "\r\n";
        } else {
            $header .= 'Reply-to: <' . $replyTo . ">\r\n";
        }
    }
    $eh = new ErrorHandler();
    set_error_handler(array($eh, "handle_mail_error"));
    $res = false;
    if (!$header) {
        $res = mail($to, $subject, $body);
    } else {
        $res = mail($to, $subject, $body, $header);
    }
    restore_error_handler();
    return array('mailed' => $res, 'errors' => $eh->errorstack, "message" => nl2br($eh->getErrorMessage()));
}
Exemplo n.º 2
0
 /**
  * This function is used to standardize the communication between the classes. All the error responses between
  * the classes should be of this format.
  *
  * Please use this for all the communications between the classes. Interactions within a class can be of any kind.
  *
  * @see ErrorHandler
  * @param $code integer should be a valid code from the ErrorHandler class or a code with a message.
  * @param null $message string if the code exists in the ErrorHandler class the message associated with it will bw returned.
  * @return array the array will have error_code and the message in it.
  */
 protected function returnError($code, $message = null)
 {
     $message = $message === null ? ErrorHandler::getErrorMessage($code) : $message;
     $this->putLog("Error {$code}: {$message}");
     return array('error' => $code, "message" => $message);
 }