So I ended up getting this working! I am posting the function with my updated code below in case someone wants to make this modification in the future.
A few notes, I changed the DBname because I believe it will be different for each instance. I also removed passwords and other personal-ish information. For our use case we wanted it to only go out to internal cc collaborators so I have it only sending the email when a persons email address contains our domain. Anyone re-using this code may want to remove that portion and just have it send the email.
Edit was made in ajax.thread.php, osticket version 1.12.5
`function _addcollaborator($thread, $user=null, $form=null, $type=null, $info=array()) {
global $thisstaff;
$info += array(
'title' => __('Add a collaborator'),
'action' => sprintf('#thread/%d/add-collaborator/%s',
$thread->getId(), $type),
'onselect' => sprintf('ajax.php/thread/%d/add-collaborator/%s/',
$thread->getId(), $type),
);
ob_start();
include STAFFINC_DIR . 'templates/user-lookup.tmpl.php';
$resp = ob_get_contents();
ob_end_clean();
//**********************************************************************************************
// CUSTOM CODE
// The goal of this is to send an email to to a CC colaborater when they are added
//Get ticket ID
$ticketID = print_r($thread->_object->ht[ticket_id],true);
//Sql query to get some thread details
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "helpdesk_dbName";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT subject FROM ost_ticket__cdata WHERE ticket_id = " . $ticketID;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$ticketSubj= $row["subject"];;
}
} else {
$ticketSubj = "";
}
$conn->close();
// Get to address
$to = $user->_email->email;
//Message Headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: system@domain.com" . "\r\n";
//create body of message
$body = "<html>
<body>
<p>
<strong>Dear " . str_replace('"',"",print_r($user->_email->address,true)).",</strong></br>
Our customer care team has added you as a collaborator on a ticket,
<a href=http://192.168.1.125/tickets.php?id=" . print_r($thread->_object->ht[ticket_id],true) . "> #" . print_r($thread->_object->ht[number],true) . "</a>
with the following details and summary: </br></br>
Topic: <strong>" . print_r($thread->_object->ht[topic]->ht[topic],true) . "</strong>
</br>
Subject: <strong>" . $ticketSubj . "</strong>
</p>
</body>
</html>";
// This is so the notification only get sent to users with a company Email address
$mailDomains = array("domain1.com", "domain2.com", "domain3.com");
foreach ($mailDomains as $domainName) {
if (stripos($to, $domainName) !== false) {
//send a link to the ticket
mail($to, "Collaborator Notification", $body, $headers);
}
}
//**********************************************************************************************
return $resp;
}`