It looks like you're new here. If you want to get involved, click one of these buttons!
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
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.
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?
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
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?
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.
Here's a complete patch against 1.6 ST. It works with imap / pop not pipe.
C
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,
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...
$vars['note'] = $body;
return $ticket->postNote($vars, $errors, $poster);
with
$vars['message'] = $body;
return $ticket->postMessage($vars, 'Email');
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;
}