@JuVDC, your question seemed interesting to me, so I spent more time for it.
Edit all names as needed.
Here you go:
1. Creare a database cis_extra.
2. In this database crate a table cis_department_change. Columns: id (index, auto increment), department_id (integer) and email (varchar).
3. Fill this table with data. Department ID according to ost_department, e-mail for each agent as you want.
4. Create a directory in the osTicket root folder for your own scripts if you don't already have one. In my case PH_scripts.
5. In this directory create connect_db_extra.php and send_dept_assign_mail.inc.php files.
6. Contents of the file connect_db_extra.php (change your login information and database name):
<?php
$server="localhost";
$username="root";
$passwort="123456";
/////////////////////////////////////////////////////////////////////////////////////////
$Connection = mysqli_connect($server,$username,$passwort);
if (!$Connection) die ("Not connected with MySQL");
//else echo ("Connected with MySQL.<br>");
$Database=mysqli_select_db($Connection, "cis_extra"); //Change database name here
mysqli_query($Connection, "set names utf8"); //Setting the display of UTF-8 characters
if(!@Database) die ("Not connectedd with database cis_extra.");
//else echo ("Connected with database cis_extra.<br>");
?>
7. Contents of the file send_dept_assign_mail.inc.php:
<?php
require '../PH_scripts/connect_db_extra.php'; //Change folder name here
//Change table name here
if(!$cis_department_change = mysqli_query($Connection, "SELECT * FROM cis_department_change WHERE `department_id` = \"$dept->getid()\"")) {$error = "Not connected with table cis_department_change.\n"; break;}
while($zaznam = mysqli_fetch_array($cis_department_change))
{
$mailto = $zaznam["email"]; //We got a e-mail address
}
//Change subject and body here
$mailsubject = "Ticket assigned to department";
$mailbody = "Ticket <a href='http://cis-ticket/scp/tickets.php?id=".$this->getId()."'>".$this->getId()."</a> has been assigned to your department.";
// To send HTML mail, the Content-type header must be set
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\r\n";
$headers .= "From: change@me.eu>" . "\r\n"; //Change address here
$headers .= "X-Mailer: php-mailer";
$encoded_subject = mb_encode_mimeheader($mailsubject,"UTF-8"); //Subject encoded in UTF-8
mail($mailto, $encoded_subject, $mailbody, $headers);
//LOG
$dt = new DateTime();
$deskriptor = fopen ("../PH_scripts/LOG_SendMailDepartment.txt","a"); //Change folder name here
fwrite ( $deskriptor ,("=================================================== "."\n"));
fwrite ( $deskriptor ,($dt->format('Y-m-d H:i:s')."\n"));
fwrite ( $deskriptor ,("Ticket ID: ".$this->getId()."\n"));
fwrite ( $deskriptor ,("To: ".$mailto."\n"));
fwrite ( $deskriptor ,("Subject: ".$mailsubject."\n"));
fwrite ( $deskriptor ,("Body: ".$mailbody."\n"));
fwrite ( $deskriptor ,("Status: ".error_get_last()['message']."\n"));
fwrite ( $deskriptor ,("=================================================== "."\n"));
fclose ( $deskriptor );
?>
8. Add INCLUDE in \include\class.ticket.php as follow, in my case line 2350:
if ($this->isAssigned()
&& ($staff=$this->getStaff())
&& $dept->assignMembersOnly()
&& !$dept->isMember($staff)
) {
$this->staff_id = 0;
}
include '../PH_scripts/send_dept_assign_mail.inc.php'; //Add this line
}
You can change everything as you want. That's how I use it, because when updating osTicket it is necessary to add only one line in the core files. The database and the script folder do not change.
Perhaps I have not forgotten anything. Ask, if you need.