2010-09-02 111 views

回答

1

看起來你可能不走運。看看osTicket的this forum post。在發送之前HTML會從電子郵件中刪除。

3

修改在class.ticket.php

  1. 添加這個新功能

    功能getHtmlEmailTemplate(){ 返回$這 - >配置[ 'html_email_template']; }

  2. 在UpdatePref()函數此行添加到$ SQL變種...

    'spoof_default_smtp ='。db_input(($變種[ 'default_smtp_id'] & & isset($變種[」 spoof_default_smtp']))?1:0)。

修改在class.email.php

  1. 通過這個替換您發送()函數:
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.-添加你想要的表

<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代碼/設置頁面這使您可以爲模板編寫自己的HTML代碼。只需鍵入%消息,你想將消息放入模板中:)

相關問題