是否可以在osTicket中使用HTML电子邮件?

时间:2010-09-02 17:40:59

标签: email-integration

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

2 个答案:

答案 0 :(得分:3)

class.ticket.php

中的修改
  1. 添加新功能

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

  2. 在UpdatePref()函数...

    中将此行添加到$ sql var

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

  3. class.email.php

    中的修改
    1. 用以下方法替换您的Send()函数:
    2. 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>
      

      最后,您在Preferences / Settings页面上有一个TextArea,允许您为模板编写自己的HTML代码。只需在要将消息放入模板的位置键入%message:)

答案 1 :(得分:1)

看起来你可能运气不好。从osTicket看一下this forum post。在发送之前,HTML会从电子邮件中删除。