function mail_report($log) { /* Mail detailed reports on what has been done. */ global $cfg, $log_header, $log_footer, $total_error_count; // Get configuration options $email_report = $cfg['email_report']; $email_archive = $cfg['email_archive']; $email_from = $cfg['email_from']; $email_to = $cfg['email_to']; $email_agent = $cfg['email_agent']; $email_smtp_host = $cfg['email_smtp_host']; $email_smtp_port = $cfg['email_smtp_port']; $ftp_upload = $cfg['ftp_upload']; $archive_tar = $cfg['archive_tar']; $archive_prefix = $cfg['archive_prefix']; $archive_gzip = $cfg['archive_gzip']; require_once dirname(__FILE__) . '/Rmail.php'; $mail = new Rmail(); // HTML Part of the Message $html = $log_header . $log['html'] . $log_footer; // Plain Vanilla Text Version of Message // $text = strip_tags(html_entity_decode($log)); $text = $log['text']; // Do we have to send the backup-archive too? if ($email_archive == TRUE && $archive_tar == TRUE) { foreach ($cfg['db'] as $db_i => $db_name) { if ($cfg['db'][$db_i]['db_name'] != '') { $db_name = $cfg['db'][$db_i]['db_name']; $db_backup_fname = $archive_prefix . $db_name . ".tar"; // Is the backup-archive compressed? if ($archive_gzip == TRUE) { $db_backup_fname .= ".gz"; $db_backup_ftype = 'application/x-gzip'; } else { $db_backup_ftype = 'application/x-tar'; } // if ($db_backup_gzip == TRUE) if (file_exists(DB_BACKUP_PATH . "/" . $db_backup_fname)) { log_msg(date("H:i:s") . ": Preparing file attachment {$db_backup_fname} \n", 10); // Add an attachment to the email $mail->addAttachment(new fileAttachment(DB_BACKUP_PATH . "/" . $db_backup_fname, $db_backup_ftype)); } else { log_msg(date("H:i:s") . ": Error: File {$db_backup_fname} for mail attachement not found!\n", 20); } // if (file_exists($db_backup_fname)) } // if ($cfg['db'][$db_i]['db_name'] != '') } // foreach ($db_backup_dbnames as $db_name) } // if (($db_backup_email == TRUE) && ($db_backup_tar == TRUE)) /* * Add the text, html and embedded images. * The name (background.gif in this case) * of the image should match exactly * (case-sensitive) to the name in the html. */ $mail->setHTML($html); $mail->setText($text); /* * Set the return path of the message */ if (ini_get('safe_mode') == "") { $mail->setReturnPath($email_from); } /** * Set some headers */ $mail->setFrom('"MySQL Database Backup" <' . $email_from . '>'); $mail->setSubject('MySQL Backup on ' . DB_BACKUP_HOST . ' of ' . date("D j. F Y")); $mail->setHeader('Date', date("r")); $mail->setHeader('X-Mailer', 'MySQL Database Backup $Revision: 1.4 $'); if ($total_error_count > 0) { $mail->setHeader('Importance', 'High'); $mail->setHeader('X-Priority', '1 (Highest)'); $mail->setHeader('X-MSMail-Priority', 'High'); $mail->setHeader('X-Message-Flag', 'There were errors! Review the protocol'); $mail->setHeader('Reply-By', date("r")); } else { $mail->setHeader('Importance', 'Low'); $mail->setHeader('X-Priority', '5 (Lowest)'); $mail->setHeader('X-MSMail-Priority', 'Low'); $mail->setHeader('Expires', date("r", time() + UNIX_DAY * 7)); $mail->setHeader('Expiry-Date', date("r", time() + UNIX_DAY * 7)); } /** * If you're using Windows you should *always* use * the smtp method of sending, as the mail() function is buggy. */ if ($email_agent == 'smtp') { // Send by connecting to an STMP server of choice. $mail->setSMTPParams($email_smtp_host, $email_smtp_port, DB_BACKUP_HOST); $result = $mail->send(array($email_to), 'smtp'); // These errors are only set if you're using SMTP to send the message if (!$result) { $msg = "Mail sending failed with the following error(s):\n"; foreach ($mail->errors as $str) { $msg .= $str . "\n"; } } else { $msg = 'Mail was sent succesfully!'; } } else { if ($email_agent == 'mail') { // Send using the built-in mail() function of PHP and Operating System $result = $mail->send(array($email_to), 'mail'); if (!$result) { $msg = "Error: Mail sending failed!\n"; } else { $msg = 'Mail was sent succesfully!'; } } else { $msg = "Error: Unknown mail agent option {$email_agent}"; } } // if ($email_agent == 'smtp') return $msg; }