Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

[MOD] Enable staff to respond via email instead of web

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::is_email($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::stripEmptyLines($parser->getBody())) && $subj)
$body=$subj;

$var['email']=$from->mailbox.'@'.$from->host;
$var['mid']=$parser->getMessageId();
$var['message']=utf8_encode(Format::stripEmptyLines($body));
$var['subject']=$subj?$subj:'[No Subject]';

$ticket=null;
if(preg_match (\"[[#][0-9]{1,10}]\",$var['subject'],$regs)) {
$extid=trim(preg_replace(\"/[^0-9]/\", \"\", $regs[0]));
$ticket= new Ticket(Ticket::getIdByExtId($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['message'],$tag))
list($message)=split($tag,$var['message']);

$sql=sprintf(\"SELECT * FROM \".STAFF_TABLE.\" WHERE `email`='%s' \",$var['email']);
$res=db_query($sql);
if(!$res) api_exit(EX_DATAERR,'Query ['.$sql.'] failed in lookup!!!!');
$resarray=db_fetch_array($res);

$staff=new Staff($resarray['staff_id']);
if(!$staff) api_exit(EX_DATAERR,'Email ['.$var['email'].'] 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['msg_id'];

//if(!($msgid=$ticket->postEmailResponse($staff,$var['mid'],$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::striptags($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['tmp_name'])) && $cfg->emailAttachments()) {
$file=array('file'=>$attachment['tmp_name'], 'name'=>$attachment['name'], 'type'=>$attachment['type']);
}

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::alertAdmin('System Error',$msg);
}
return $resp_id;
endif;

return 0;
//api_exit(EX_DATAERR,'DB query failed in post email response');
}

Comments

  • If this works the way I think it works, you are an absolute saviour!

    So with this installed, let's say a customer emails in, and a ticket is created automatically. I can then send an email to the support address (from my registered email), containing the ticket number in the subject, and it will update the case and send an update notification to the customer?

    Thanks very much in advance if that's what it does as the mobile browser on the BB is not the easiest interface, even with the detect mobile apps mod applied.
  • That is exactly what it does. LOL, I did this for the same reason, to be able to use my blackberry to respond to support issues.
  • CMY;21744 said:
    That is exactly what it does. LOL, I did this for the same reason, to be able to use my blackberry to respond to support issues.
    Good work, thanks!

    However I got this when I tried to reply to a case - and it sent a blank email:


    [INSERT INTO ost_ticket SET created=NOW() ,ticketID=175833,dept_id=1,topic_id='0',priority_id=2,email='abc@xyz.com',emailcc='',name='abc@xyz.com',subject='Help me',helptopic='',phone="",phone_ext='',ip_address='1.2.3.4',source='Email']

    Unknown column 'emailcc' in 'field list'


    emailcc is something I don't have - do you have any other mods on yours that might have put that field in your db?
  • cde3879;21748 said:
    Good work, thanks!

    However I got this when I tried to reply to a case - and it sent a blank email:


    [INSERT INTO ost_ticket SET created=NOW() ,ticketID=175833,dept_id=1,topic_id='0',priority_id=2,email='abc@xyz.com',emailcc='',name='abc@xyz.com',subject='Help me',helptopic='',phone="",phone_ext='',ip_address='1.2.3.4',source='Email']

    Unknown column 'emailcc' in 'field list'


    emailcc is something I don't have - do you have any other mods on yours that might have put that field in your db?
    I have the Email CC MOD installed as well. If you are decent with PHP you can remove those lines and change them back to original or you can add the emailcc column to the table. Here is the command:

    ALTER TABLE `ost_ticket` ADD `emailcc` TEXT NOT NULL AFTER `email`
  • Pipe Creating New Ticket

    Hi,

    I added both sets of your code to the bottom of my pipe.php and class.ticket.php files. However, when staff to a ticket, the pipe is creating a "new" ticket instead of adding the reply to the existing ticket. Any ideas?

    -Luke
  • CMY;21739 said:
    Here is a mod I did to allow staff to respond to support tickets from the new message alerts (if they are enabled).
    Hello, thank you for your great commitment. However, I added your code and still get new tickets on staff reply. Do you have any idea, how to fix the problem?
  • When sending the reply are they sending from the email that they have registered in osTicket and are they including the ticket number in the subject in the standard format [#xxxx]?
  • A new ticket is made when I reply

    Hi,

    I have the same problem as Bookit. There is a default System address, a default Alert address and a system admin email address.

    To whom and from whom exactly must this mail be sent for this to work?

    Also my hostname is support.mydomain.com and my emailadresses are [email]username@mydomain.com[/email]. Could this be the issue?
  • This mod half works for me. If a user replies through email (which already has the ticket number in the subject line) it works. If a staff member replies (the ticket id has to be added to the subject line) it does not work.
  • Creating new tickets

    I'm also having trouble getting this to work properly. When staff responds to new ticket alert via email, OSTicket is creating new tickets (RE: [#XXXXXX]). I have checked to be sure that they are using their registered email address and that the ticket number is is formatted properly in the subject line. Software version is 1.6 ST.
  • Hi,

    Here's a complete patch against 1.6 ST. It works with imap / pop not pipe.

    C
  • I can not gets this to work. I am still getting new emails created when I reply to a ticket via email. Also, it killed my gui access to the scp. Suggestions?
  • 1. Tested with Original pipe.php and class.ticket.php. New Ticket created in osTicket when sending email to [email]support@domain.com[/email]. [email]support@domain.com[/email] set to be Default System Email and Outgoing Email. Both sender and Support Staff received [# 123456] New Ticket Alert for Support Staff and [# 123456 Support Ticket Opened for Sender in their email subject. Tried reply directly from New Ticket Alert email. Failed as expected.

    2. Replaced both pipe.php and class.ticket.php with the one attached in your 1st post.
    3. Send email to [email]support@domain.com[/email] and osTicket created new ticket but both Sender and Support Staff received Blank Subject and Content suppose to appear in Subject, appeared in Email Body.
    4. I have not try to send directly from email but I believe it won't work with empty Email Subject.

    Please advice,
  • this mod sends an email with no subject and the msg is "new ticket alert"
  • Hello,

    Am using osTicket v1.7.0 will this code work on it ? i have checked the files but it does not seems having same architecture...

    Does anyone have solution for the version osTicket v1.7.0 ?

    Thanks in advance...
  • edited August 2014
    You can replace two lines in v1.9 to enable staff to respond via email instead of web. Open include\class.thread.php and replace
                $vars['note'] = $body;
                return $ticket->postNote($vars, $errors, $poster);
    with
             $vars['message'] = $body;
             return $ticket->postMessage($vars, 'Email');  
     


  • edited September 2014
    Hey sober,

    Was replacing those two lines all you had to do to enable staff respond via email for v1.9 or did you follow the same steps CMY initially posted in addition to those two lines?
  • Yes, I partially followed the same steps CMY initially posted in addition to those two lines. I changed only:
    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::is_email($fromobj->mailbox.'@'.$fromobj->host))
    continue;
    while (list($spptemail)=db_fetch_row($spptemailquery)){
    if(strtolower($spptemail)==strtolower($fromobj->mailbox.'@'.$fromobj->host)){
    $spptemailresponse=true;
    }
    }
    break;
    }

Sign In or Register to comment.