Hi,
sometimes sending a mail take too much time and the browser get a timeout. Even if everything is running well the user get a blank screen and this is not good.
This modification display the thankyou page immediatly and open a popup which send the mail and close when mail is send. So that we are sure that the user get the thankyou page.
Modification in file Thankyou.inc.php
After the line please add these lines:
<script>
window.open('sendmail.php?tid=<?=$ticket->getId();?>','popup','height=120, width=300, resizable=no, toolbar=no, location=no, status=no, scrollbars=no, menubar=no');
</script>
Modification in class.ticket.php
In function create
function create($var,&$errors,$origin,$autorespond=true,$alertstaff=true) {
go to :
$dept=$ticket->getDept();
if(!$dept || !($tplId=$dept->getTemplateId()))
$tplId=$cfg->getDefaultTemplateId();
and comment the code until before the following lines :
}
return $ticket;
Below the create function add the following lines (this is only a copy of what we comment in the create function) :
function sendmailaftercreation($ticket,$autorespond,$alertstaff, &$errors) {
global $cfg,$thisclient,$_FILES;
$sql='SELECT message from '.TICKET_MESSAGE_TABLE.' WHERE ticket_id='.$ticket->getId();
if ($msgres =db_query($sql))
if ($msg_row = db_fetch_array($msgres))
$msgt = $msg_row;
else
$errors= 'cannot get message from Ticket : '.$ticket->getId();
else
$errors = 'cannot find Ticket : '.$ticket->getId();
$dept=$ticket->getDept();
if(!$dept || !($tplId=$dept->getTemplateId()))
$tplId=$cfg->getDefaultTemplateId();
//Overwrite auto responder if the FROM email is one of the internal emails...loop control.
if($autorespond && (Email:($ticket->getEmail())))
$autorespond=false;
//SEND OUT NEW TICKET AUTORESP && ALERTS.
//New Ticket AutoResponse..
if($autorespond && $cfg->autoRespONNewTicket() && $dept->autoRespONNewTicket()){
$sql='SELECT ticket_autoresp_subj,ticket_autoresp_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=$ticket->replaceTemplateVars($body);
$subj=$ticket->replaceTemplateVars($subj);
$body = str_replace('%message',($msgt),$body);
$body = str_replace('%signature',($dept && $dept->isPublic())?$dept->getSignature():'',$body);
if(!$dept || !($email=$dept->getAutoRespEmail()))
$email=$cfg->getDefaultEmail();
if($email){
//Reply separator tag.
if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()))
$body ="\n$tag\n\n".$body;
if (!$email->send($ticket->getEmail(),$subj,$body))
$errors = ' Cannot send mail to user : '.$ticket->getEmail().' '.$subj;
}
}else {
Sys:(LOG_WARNING,'Template Fetch Error',"Unable to fetch autoresponse template #$tplId");
}
}
//If enabled...send alert to staff (New Ticket Alert)
if($alertstaff && $cfg->alertONNewTicket() && is_object($ticket)){
$sql='SELECT ticket_alert_subj,ticket_alert_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=$ticket->replaceTemplateVars($body);
$subj=$ticket->replaceTemplateVars($subj);
$body = str_replace('%message',$msgt,$body);
if(!($email=$cfg->getAlertEmail()))
$email =$cfg->getDefaultEmail();
if($email && $email->getId()) {
$sentlist=array();
//Admin Alert.
if($cfg->alertAdminONNewTicket()){
$alert = str_replace("%staff",'Admin',$body);
if (!$email->send($cfg->getAdminEmail(),$subj,$alert))
$errors = 'Can send mail to admin : '.$staff->getAdminEmail().' '.$subj;
$sentlist=$cfg->getAdminEmail();
}
//get the list
$recipients=array();
//Dept. Manager
if($cfg->alertDeptManagerONNewTicket()) {
$recipients=$dept->getManager();
}
//Staff members
if($cfg->alertDeptMembersONNewTicket()) {
$sql='SELECT staff_id FROM '.STAFF_TABLE.' WHERE onvacation=0 AND dept_id='.db_input($dept->getId());
if(($users=db_query($sql)) && db_num_rows($users)) {
while(list($id)=db_fetch_row($users))
$recipients= new Staff($id);
}
}
foreach( $recipients as $k=>$staff){
if(!$staff || !is_object($staff) || !$staff->isAvailable()) continue;
if(in_array($staff->getEmail(),$sentlist)) continue; //avoid duplicate emails.
$alert = str_replace("%staff",$staff->getFirstName(),$body);
if (!$email->send($staff->getEmail(),$subj,$alert))
$errors = 'Can send mail to staff : '.$staff->getEmail().' '.$subj;
$sentlist=$staff->getEmail();
}
}
}else {
Sys:(LOG_WARNING,'Template Fetch Error',"Unable to fetch 'new ticket' alert template #$tplId");
}
}
return $errors;
}
create the following file at the top of the server :
sendmail.php
<?php
/*********************************************************************
sendmail.php
Asynchronous send mail.
David ANDRE
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
$Id: $
**********************************************************************/
require('client.inc.php');
$errors=array();
?>
<html>
<head>
<meta http-equiv="refresh" content="0; url=sendmail.inc.php?tid=<?=$_GET;?>" />
</head>
<BODY>
<center>
<b><i>Sending email</i></b>
<img src="images/wait.gif" border=0>
</center>
</BODY>
</HTML>
Find on internet a nice gif to display.
Create the following file at the top of the server :
sendmail.inc.php
<?php
/*********************************************************************
sendmail.inc.php
Asynchron send mail.
David ANDRE
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
$Id: $
**********************************************************************/
require('client.inc.php');
$errors=array();
if($_GET){
if ($ticket= new Ticket($_GET,false)){
?>
<?=ticket:($ticket,$errors);?>
<?
}
}else{
?>
erreur
<?}?>
<HTML>
<BODY>
<center><b><I>
Email sent</i></b>
</center>
<script>
document.close;
</script>
</BODY>
</HTML>
that's it. you can check that now.