'; $headers['Return-Path'] = 'observium@' . $localhost; } else { // Validate configured mail from foreach(parse_email($cfg['from']) as $from => $from_name) { $headers['From'] = (empty($from_name) ? $from : '"' . $from_name . '" <' . $from . '>'); // From: $headers['Return-Path'] = $from; break; // use only first entry } } $rcpts = []; $rcpts_full = []; foreach ($emails as $to => $to_name) { $rcpts_full[] = (empty($to_name) ? $to : '"' . trim($to_name) . '" <' . $to . '>'); $rcpts[] = $to; } $rcpts_full = implode(', ', $rcpts_full); $rcpts = implode(', ', $rcpts); $headers['To'] = $rcpts_full; // To: $headers['Subject'] = $message_tags['TITLE']; // Subject: // ID and Date, leave it before X- headers $headers['Message-ID'] = '<' . md5(uniqid(time(), TRUE)) . '@' . $localhost . '>'; $headers['Date'] = $time_rfc; $headers['X-Priority'] = 3; // Mail priority $headers['X-Mailer'] = OBSERVIUM_PRODUCT . ' ' . OBSERVIUM_VERSION; // X-Mailer: // Mail autogenerated, suppress autorespond by any issue system $headers['Precedence'] = 'bulk'; $headers['Auto-submitted'] = 'auto-generated'; $headers['X-Auto-Response-Suppress'] = 'All'; $time_sent = $time_rfc; // Creating the Mime message $mime = new Mail_mime(['head_charset' => 'utf-8', 'text_charset' => 'utf-8', 'html_charset' => 'utf-8', 'eol' => PHP_EOL]); // Mail text footer $message_tags['FOOTER'] = "\n\nE-mail sent to: $rcpts\n" . "E-mail sent at: $time_sent\n\n" . "-- \n" . OBSERVIUM_PRODUCT_LONG . ' ' . OBSERVIUM_VERSION . "\n" . OBSERVIUM_URL . "\n"; // Generate Mail text in both plain text and html $message['text'] = simple_template('email_text', $message_tags, [ 'is_file' => TRUE ]); $message_tags_html = $message_tags; $message_tags_html['CONDITIONS'] = nl2br(escape_html($message_tags['CONDITIONS'])); $message_tags_html['METRICS'] = nl2br(escape_html($message_tags['METRICS'])); // Generate image attach //$graphs = json_decode($message_tags_html['ENTITY_GRAPHS_ARRAY'], TRUE); $graphs = $message_tags_html['ENTITY_GRAPHS_ARRAY']; if (is_array($graphs) && count($graphs)) { $message_tags_html['ENTITY_GRAPHS'] = ''; // Reinit graphs html foreach ($graphs as $key => $graph) { $cid = random_string(16); // Unencode data uri tag to file content [ $gmime, $base64 ] = explode(';', $graph['data'], 2); $gmime = substr($gmime, 5); $base64 = substr($base64, 7); //print_vars(substr($graph['data'], 0, 20)); //print_vars($gmime); //print_vars(substr($base64, 0, 20)); $mime->addHTMLImage(base64_decode($base64), $gmime, $cid . '.png', FALSE, $cid); $message_tags_html['ENTITY_GRAPHS'] .= '

' . $graph['type'] . '

'; $message_tags_html['ENTITY_GRAPHS'] .= '
'; } } //print_vars($message_tags_html); // Mail html footer $message_tags_html['FOOTER'] = "\n

E-mail sent to: $rcpts
\n" . "E-mail sent at: $time_sent

\n" . '
--
' . OBSERVIUM_PRODUCT_LONG . ' ' . OBSERVIUM_VERSION . "
\n"; $message['html'] = simple_template('email_html', $message_tags_html, [ 'is_file' => TRUE ]); unset($message_tags_html); foreach ($message as $part => $part_body) { switch ($part) { case 'text': case 'txt': case 'plain': $mime->setTXTBody($part_body); break; case 'html': $mime->setHTMLBody($part_body); break; //case 'image': // break; //case 'attachment': // break; } } $body = $mime->get(); // Prepare headers foreach ($headers as $name => $value) { $headers[$name] = $mime->encodeHeader($name, $value, 'utf-8', 'quoted-printable'); } $headers = $mime->headers($headers); //var_dump($headers); // Create mailer instance $mail = Mail::factory($backend, $mail_params); // Sending email $status = $mail->send($rcpts, $headers, $body); if (PEAR::isError($status)) { //print_message('%rMailer Error%n: ' . $status->getMessage(), 'color'); $notify_status['success'] = FALSE; $notify_status['error'] = $status->getMessage(); } else { $notify_status['success'] = TRUE; } unset($message); // EOF