osticket html email templates
Modifications in class.ticket.php
Add this new function
function getHtmlEmailTemplate(){ return $this->config; }
add this line to $sql var at UpdatePref() function...
',spoof_default_smtp='.db_input(($var && isset($var))?1).
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", '', $body), $cfg->getHtmlEmailTemplate());
$fromname=$this->getName();
$from =sprintf('"%s"',($fromname?$fromname:$this->getEmail()),$this->getEmail());
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject,
'Date'=>date('D, d M Y H O'),
'Message-ID' =>'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 && is_readable($attachment)) {
$mime->addAttachment($attachment,$attachment,$attachment);
}
$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:('smtp',
array ('host' => $smtp,
'port' => $smtp,
'auth' => $smtp?true,
'username' => $smtp,
'password' => $smtp,
'timeout' =>20,
'debug' => false,
));
$result = $mail->send($to, $headers, $body);
if(!PEAR:($result))
return true;
$alert=sprintf("Unable to email via %s:%d \n\n%s\n",$smtp,$smtp,$smtp,$result->getMessage());
Sys:(LOG_ALERT,'SMTP Error',$alert,false);
//print_r($result);
}
//No SMTP or it failed....use php's native mail function.
$mail = mail:('mail');
return PEAR:($mail->send($to, $headers, $body))?false;
}
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", '', $body), $cfg->getHtmlEmailTemplate());
$headers = array ('From' =>$from,
'To' => $to,
'Subject' => $subject,
'Message-ID' =>'',
'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:('mail');
return PEAR:($mail->send($to, $headers, $body))?false;
}
Modifications in preference.inc.php
1.- Add this HTML code where you want inside the table
HTML Email Template:
<?=$config?>Will be used for all outgoing emails.Insert %message where you want the message text to be replaced in the template.
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 :)