Изменения в class.ticket.php
Добавить эту новую функцию
function getHtmlEmailTemplate () {return$ this-> конфигурации [ 'html_email_template'];}
добавить эту строку в $ sql var в функции UpdatePref () ...
', spoof_default_smtp ='. Db_input (($ var ['default_smtp_id']&& isset ($ var ['spoof_default_smtp']))? 1: 0).
Изменения в class.email.php
- Замените функцию 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, где вы хотите поместить сообщение в шаблон:)