osTicket是否支持HTML邮件?

4

我有一个电子邮件模板,用于发送账户电子邮件,我想通过osTicket使用相同的HTML电子邮件模板..这可能吗?


你好,你是否曾经在osticket的外发邮件中嵌入HTML代码? - Anagio
2个回答

3

class.ticket.php 中的修改

  1. 添加这个新函数

    function getHtmlEmailTemplate(){ return $this->config['html_email_template']; }

  2. 在 UpdatePref() 函数的 $sql 变量中添加以下行...

    ',spoof_default_smtp='.db_input(($var['default_smtp_id'] && isset($var['spoof_default_smtp']))?1:0).

class.email.php 中的修改

  1. 使用以下函数替换您的 Send() 函数:
function send($to,$subject,$message,$attachment=null) {
        global $cfg;

        //Get SMTP info IF enabled!
        $smtp=array();
        if($this->isSMTPEnabled() && ($info=$this->getSMTPInfo())){ 
            $smtp=$info;
        }elseif($cfg && ($email=$cfg->getDefaultSMTPEmail()) && $email->isSMTPEnabled()){ //What about global SMTP setting?
            if($cfg->allowSMTPSpoofing() && ($info=$email->getSMTPInfo())){ 
                $smtp=$info;
            }elseif($email->getId()!=$this->getId()){
                return $email->send($to,$subject,$message,$attachment);
            }
        }

        //Get the goodies
        require_once ('Mail.php'); // PEAR Mail package
        require_once ('Mail/mime.php'); // PEAR Mail_Mime packge

        //do some cleanup
        $eol="\n";
        $to=preg_replace("/(\r\n|\r|\n)/s",'', trim($to));
        $subject=stripslashes(preg_replace("/(\r\n|\r|\n)/s",'', trim($subject)));
        $body = stripslashes(preg_replace("/(\r\n|\r)/s", "\n", trim($message)));
        $htmlbody = str_replace('%message', str_replace("\n", '<br />', $body), $cfg->getHtmlEmailTemplate());
        $fromname=$this->getName();
        $from =sprintf('"%s"<%s>',($fromname?$fromname:$this->getEmail()),$this->getEmail());
        $headers = array ('From' => $from,
                          'To' => $to,
                          'Subject' => $subject,
                          'Date'=>date('D, d M Y H:i:s O'),
                          'Message-ID' =>'<'.Misc::randCode(6).''.time().'-'.$this->getEmail().'>',
                          'X-Mailer' =>'osTicket v 1.6',
                          'Content-Type' => 'text/html; charset="UTF-8"'
                          );
        $mime = new Mail_mime();
        $mime->setTXTBody($body);
        if (strpos($cfg->getHtmlEmailTemplate(), '%message') !== false) 
          $mime->setHTMLBody($htmlbody);
        //attachment TODO: allow multiple attachments - $attachment should be mixed parts.
        if($attachment && $attachment['file'] && is_readable($attachment['file'])) { 
            $mime->addAttachment($attachment['file'],$attachment['type'],$attachment['name']);
        }
        $options=array('head_encoding' => 'quoted-printable',
                       'text_encoding' => 'quoted-printable',
                       'html_encoding' => 'base64',
                       'html_charset'  => 'utf-8',
                       'text_charset'  => 'utf-8');
        //encode the body
        $body = $mime->get($options);
        //encode the headers.
        $headers = $mime->headers($headers);
        if($smtp){ //Send via SMTP
            $mail = mail::factory('smtp',
                    array ('host' => $smtp['host'],
                           'port' => $smtp['port'],
                           'auth' => $smtp['auth']?true:false,
                           'username' => $smtp['username'],
                           'password' => $smtp['password'],
                           'timeout'  =>20,
                           'debug' => false,
                           ));
            $result = $mail->send($to, $headers, $body);
            if(!PEAR::isError($result))
                return true;

            $alert=sprintf("Unable to email via %s:%d [%s]\n\n%s\n",$smtp['host'],$smtp['port'],$smtp['username'],$result->getMessage());
            Sys::log(LOG_ALERT,'SMTP Error',$alert,false);
            //print_r($result);
        }

        //No SMTP or it failed....use php's native mail function.
        $mail = mail::factory('mail');
        return PEAR::isError($mail->send($to, $headers, $body))?false:true;

    }

2.- 用以下代码替换您的sendmail()函数:

function sendmail($to,$subject,$message,$from) {

        require_once ('Mail.php'); // PEAR Mail package
        require_once ('Mail/mime.php'); // PEAR Mail_Mime packge

        $eol="\n";
        $to=preg_replace("/(\r\n|\r|\n)/s",'', trim($to));
        $subject=stripslashes(preg_replace("/(\r\n|\r|\n)/s",'', trim($subject)));
        $body = stripslashes(preg_replace("/(\r\n|\r)/s", "\n", trim($message)));
        $htmlbody = str_replace('%message', str_replace("\n", '<br />', $body), $cfg->getHtmlEmailTemplate()); 
        $headers = array ('From' =>$from,
                          'To' => $to,
                          'Subject' => $subject,
                          'Message-ID' =>'<'.Misc::randCode(10).''.time().'@osTicket>',
                          'X-Mailer' =>'osTicket v 1.6',
                          'Content-Type' => 'text/html; charset="UTF-8"'
                          );
        $mime = new Mail_mime();
        $mime->setTXTBody($body);
        if (strpos($cfg->getHtmlEmailTemplate(), '%message') !== false) 
          $mime->setHTMLBody($htmlbody);
        $options=array('head_encoding' => 'quoted-printable',
                       'text_encoding' => 'quoted-printable',
                       'html_encoding' => 'base64',
                       'html_charset'  => 'utf-8',
                       'text_charset'  => 'utf-8');
        //encode the body
        $body = $mime->get($options);
        //headers
        $headers = $mime->headers($headers);
        $mail = mail::factory('mail');
        return PEAR::isError($mail->send($to, $headers, $body))?false:true;
    }

preference.inc.php文件的修改

1.- 在表格中任意位置添加以下HTML代码

<tr><th>HTML Email Template:</th>
          <td><textarea rows="15" name="html_email_template" style="width:600px;"><?=$config['html_email_template']?></textarea><br><i>Will be used for all outgoing emails.<br />Insert %message where you want the message text to be replaced in the template.</i></td>
        </tr>

最后,在“首选项/设置”页面上,您可以获得一个TextArea,使您能够编写自己的HTML代码模板。只需在模板中输入%message,即可将消息放置到所需位置:)


1

看起来你可能运气不佳。请查看osTicket的这篇论坛帖子。在发送电子邮件之前,HTML将被剥离。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接