Jump to content

Send Email on Ticket Note (no longer working)


Atomic

Recommended Posts

I had a hook made years ago that sends an email to techs when a note is made. We just moved our installation to a new server and new domain. WHMCS version is the same (v6) and the only change was a move from PHP 5.2 to 5.6. This is the code, can anyone see any problems with it?

<?php
if (!defined("WHMCS"))
   die("This file cannot be accessed directly");

function emailonaddticketnote_SendEmail($fromemail,$toemail, $fromname, $toname, $subject, $message)
{
 global $CONFIG;

 if($CONFIG['LogoURL'])
 {
   $sendmessage = '<p><a href="'.$CONFIG['Domain'].'" target="_blank"><img src="'.$CONFIG['LogoURL'].'" alt="'.$CONFIG['CompanyName'].'" border="0"></a></p>';
 }

 $sendmessage .= '<font style="font-family:Verdana;font-size:11px"><p>'.$message.'</p>';

 $mail = new PHPMailer();

 $mail->From = $fromemail;
 $mail->FromName = $fromname;
 $mail->Subject = $subject;
 $mail->CharSet = $CONFIG['Charset'];

 if($CONFIG['MailType'] == "mail")
 {
   $mail->Mailer = "mail";
 }
 elseif($CONFIG['MailType'] == "smtp") 
 {
   $mail->IsSMTP();
	$mail->Host = $CONFIG['SMTPHost'];
	$mail->Port = $CONFIG['SMTPPort'];
	$mail->Hostname = $_SERVER['SERVER_NAME'];

   if($CONFIG['SMTPSSL']) 
	{
    $mail->SMTPSecure = $CONFIG['SMTPSSL'];
	}

   if($CONFIG['SMTPUsername']) 
	{
	  $mail->SMTPAuth = true;
		$mail->Username = $CONFIG['SMTPUsername'];
		$mail->Password = decrypt($CONFIG['SMTPPassword']);
	}

	$mail->Sender = $CONFIG['Email'];
	$mail->AddReplyTo($fromemail, $fromname);
 }

 $mail->AddAddress($toemail, $toname);

 $message_text = str_replace("</p>", "\r\n\r\n", $sendmessage);
 $message_text = str_replace("<br>", "\r\n", $message_text);

 $message_text = str_replace("<br />", "\r\n", $message_text);

 $message_text = strip_tags($message_text);

 $mail->Body = $sendmessage;
 $mail->AltBody = $message_text;

$mail->Send();
$mail->ClearAddresses();

 return true;		
}


function emailonaddticketnote($vars) {
   global $CONFIG;
   $companyname = $CONFIG['CompanyName'];
$whmcsurl = $CONFIG['SystemURL'];

$readmins = mysql_query("SELECT `firstname`,`lastname` FROM `tbladmins` WHERE `id`='".$vars['adminid']."'");
$data = mysql_fetch_array($readmins);

   $query = mysql_query("SELECT `id` FROM `tbladminroles` WHERE `supportemails`='1'");
   while ($row = mysql_fetch_assoc($query)) {
       $queryb = mysql_query("SELECT `email`,`firstname`,`lastname` FROM `tbladmins` WHERE `roleid`='".$row['id']."'");
       while ($result = mysql_fetch_assoc($queryb)) {
		$ticketurl = $whmcsurl."/admin/supporttickets.php?action=view&id=".$vars['ticketid'];
       	$message = "Hello ".$result['firstname'].",<br /><br />A note has been added to ticket #".$vars['ticketid']."<br /><br />Note: ".$vars['message']."<br />By admin: ".ucwords($data['firstname']." ".$data['lastname']."<br /><br />To view the ticket please click here:<br/><a href='".$ticketurl."'>".$ticketurl."</a><br /><br />Thank You,<br>".$companyname);
           $fullname = $result['firstname'].' '.$result['lastname'];
           $email = $result['email'];
           emailonaddticketnote_SendEmail($email,$email, $companyname, $fullname, 'Note added to ticket #'.$vars['ticketid'], $message);
       }
   }
}

add_hook("TicketAddNote",1,"emailonaddticketnote");

Cheers. It's a useful hook, feel free to use it and make a note and see if it works. If it does then there is a misconfig in our system due to the changeover.

Link to comment
Share on other sites

Hey Brian, one of my techs just fixed this. Under Settings > Mail we had no SSL and "localhost" set. We had to put the server hostname, SSL port and enable SSL. This system was running on cPanel before and now it's Plesk so perhaps there is some internal way that cPanel handles encrypted mail that differs to Plesk. Can't be bothered to dig into now but it works. :) Thanks for looking though!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated