Here is a mod I did to allow staff to respond to support tickets from the new message alerts (if they are enabled). You really can just send an email to your support email with the ticket number in brackets as the subject and it should work the same as long as you are sending it from your registered support/notification email for your username. It's probably a security risk for larger corporations; but for a solo developer like me, it saves me the hassle of always needing to have a pc around without losing the record keeping of osTicket. Here is the code I added, and I have a zip file of the complete modified files attached as well.
*** PS. This only works if you have piping enabled. ***
in pipe.php
//CUSTOM ADD FOR SUPPORT EMAIL REPSONSE
$spptemailresponse=false;
$spptemailquery=db_query('SELECT `email` FROM '.STAFF_TABLE); //`ost_staff`');
if(!spptemailquery) api_exit(EX_DATAERR,'Support email query failed!!!!!');
foreach($fromlist as $fromobj){
if(!Validator:($fromobj->mailbox.'@'.$fromobj->host))
continue;
while (list($spptemail)=db_fetch_row($spptemailquery)){
if(strtolower($spptemail)==strtolower($fromobj->mailbox.'@'.$fromobj->host)){
$spptemailresponse=true;
}
}
break;
}
if( $spptemailresponse ){
$subj=utf8_encode($parser->getSubject());
if(!($body=Format:($parser->getBody())) && $subj)
$body=$subj;
$var=$from->mailbox.'@'.$from->host;
$var=$parser->getMessageId();
$var=utf8_encode(Format:($body));
$var=$subj?$subj:'';
$ticket=null;
if(preg_match ("",$var,$regs)) {
$extid=trim(preg_replace("/", "", $regs));
$ticket= new Ticket(Ticket:($extid));
if(!is_object($ticket) ) //Do not do compare emails since this email is from support and not the client/customer
$ticket=null;
}
if( $ticket==null ) api_exit(EX_DATAERR,'Response to an unknown ticket!!!!');
if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()) && strpos($var,$tag))
list($message)=split($tag,$var);
$sql=sprintf("SELECT * FROM ".STAFF_TABLE." WHERE `email`='%s' ",$var);
$res=db_query($sql);
if(!$res) api_exit(EX_DATAERR,'Query failed in lookup!!!!');
$resarray=db_fetch_array($res);
$staff=new Staff($resarray);
if(!$staff) api_exit(EX_DATAERR,'Email ['.$var does not exist in the staff table!!!');
$msgidsql=sprintf('SELECT * FROM '.TICKET_MESSAGE_TABLE.' WHERE `ticket_id`=%s ORDER BY `msg_id` DESC LIMIT 1',$ticket->getId());
$msgidres=db_query($msgidsql);
$msgidarray=db_fetch_array($msgidres);
$lastmsgid=$msgidarray;
//if(!($msgid=$ticket->postEmailResponse($staff,$var,$message,'mine'))) {
if(!($msgid=$ticket->postEmailResponse($staff,$lastmsgid,$message,'mine'))) {
api_exit(EX_DATAERR,"Unable to post email response \n\n $message\n");
}
api_exit(EX_SUCCESS);
}
//END ADD
in class.ticket.php
/******* FUNCTION ADDED FOR STAFF EMAIL RESPONSE MOD *********/
//Insert Staff Reply
function postEmailResponse($thisuser,$msgid,$response,$signature='none',$attachment=false,$canalert=true){
//global $thisuser,$cfg;
global $cfg;
if(!$thisuser || !$thisuser->getId() || !$thisuser->isStaff()) //just incase
return 0;
//api_exit(EX_DATAERR,'This user incorrect in email response!!!!');
$sql= 'INSERT INTO '.TICKET_RESPONSE_TABLE.' SET created=NOW() '.
',ticket_id='.db_input($this->getId()).
',msg_id='.db_input($msgid). //Need to fix this as is showing 0 currently : Make search for last message id and use this as msgid
',response='.db_input($response). //',response='.db_input(Format:($response)).
',staff_id='.db_input($thisuser->getId()).
',staff_name='.db_input($thisuser->getName()).
',ip_address='.db_input("0.0.0.0"); //So you know response was through email and not from being logged in
$resp_id=0;
//echo $sql;
if(db_query($sql) && ($resp_id=db_insert_id())):
$this->onResponse(); //do house cleaning..
if(!$canalert) //No alert/response
return $resp_id;
$dept=$this->getDept();
if(!$dept || !($tplId=$dept->getTemplateId()))
$tplId=$cfg->getDefaultTemplateId();
//Send Response to client...based on the template...
//TODO: check department level templates...if set.
$sql='SELECT ticket_reply_subj,ticket_reply_body FROM '.EMAIL_TEMPLATE_TABLE.
' WHERE cfg_id='.db_input($cfg->getId()).' AND tpl_id='.db_input($tplId);
if(($resp=db_query($sql)) && db_num_rows($resp) && list($subj,$body)=db_fetch_row($resp)){
$body=$this->replaceTemplateVars($body);
$subj=$this->replaceTemplateVars($subj);
$body = str_replace('%response',$response,$body);
//$body = str_replace('%message',$response,$body); //Previously used!
//Figure out the signature to use...if any.
switch(strtolower($signature)):
case 'mine';
$signature=$thisuser->getSignature();
break;
case 'dept':
$signature=($dept && $dept->isPublic())?$dept->getSignature():''; //make sure it is public
break;
case 'none';
default:
$signature='';
break;
endswitch;
$body = str_replace("%signature",$signature,$body);
//Email attachment when attached AND if emailed attachments are allowed!
$file=null;
if(($attachment && is_file($attachment)) && $cfg->emailAttachments()) {
$file=array('file'=>$attachment, 'name'=>$attachment, 'type'=>$attachment);
}
if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()))
$body ="\n$tag\n\n".$body;
if(!$dept || !($email=$dept->getEmail()))
$email =$cfg->getDefaultEmail();
if($email && $email->getId()) {
//ORIGINAL
//$email->send($this->getEmail(),$subj,$body,$file);
//ADDED
$emailcc = str_replace(',','|',$this->getEmailcc());
$email->send($this->getEmail(),$emailcc,$subj,$body,$file); //Send response to client and cc list that staff has replied
}
}else{
//We have a big problem...alert admin...
$msg='Problems fetching response template for ticket#'.$this->getId().' Possible config error - template #'.$tplId;
Sys:('System Error',$msg);
}
return $resp_id;
endif;
return 0;
//api_exit(EX_DATAERR,'DB query failed in post email response');
}
[Sppt_Email_Response_MOD.zip](https://forum.osticket.com/assets/files/migrated/2/b70f9eb76ded98f04cbc4d52ae912c5.zip)