修复 Cacti 集成时邮件乱码

faq
mail
cacti

#1
  1. 打开 {cacti_home}/plugins/thold/thold_functions.php 例如:
    vim /var/www/html/cacti/plugins/thold/thold_functions.php
  2. 定位到 function thold_mail 函数,修改如下
/*增加字符转码函数*/
function onealert_charset($data){
  if( !empty($data) ){
    $fileType = mb_detect_encoding($data, array('UTF-8','GBK', 'LATIN1', 'BIG5'));
    if( $fileType != 'UTF-8') {
      $data = mb_convert_encoding($data, 'utf-8', $fileType);
    }
  }
  return $data;
}

/* Sends a group of graphs to a user */
function thold_mail($to, $from, $subject, $message, $filename, $headers = '') {
    /*添加下面两行代码对邮件标题和内容转码*/
    $subject = onealert_charset($subject);
    $message = onealert_charset($message);

    global $config;
    thold_debug('Preparing to send email');
    include_once($config['base_path'] . '/plugins/settings/include/mailer.php');
    include_once($config['base_path'] . '/plugins/thold/setup.php');

    $subject = trim($subject);

    $message = str_replace('', $subject, $message);
    ...... //此处省略
}