Is it possible to have HTML emails in osTicket?
I have an e-mail开发者_如何学C template that I use to send out account emails and I'd like to use the same HTML email template via osTicket.. is this possible?
Modifications in class.ticket.php
Add this new function
function getHtmlEmailTemplate(){ return $this->config['html_email_template']; }
add this line to $sql var at UpdatePref() function...
',spoof_default_smtp='.db_input(($var['default_smtp_id'] && isset($var['spoof_default_smtp']))?1:0).
Modifications in class.email.php
- Replace your Send() function by this one:
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.- Replace your sendmail() function by this one:
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;
}
Modifications in preference.inc.php
1.- Add this HTML code where you want inside the table
<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>
Finally you have got a TextArea at Preferences/Settings page which allow you to write your own HTML code for the template. Just type %message where you want to place the message into the template :)
It looks like you might be out of luck. Take a look at this forum post from osTicket. HTML is stripped from the email before sending.
精彩评论