Jump to content

Sending Custom Email


Recommended Posts

Because of the way WHMCS sends all Ticket Emails to main Client even if logged by a Contact, we disable the standard emails and send our own using hooks and PHPMailer so that we can only send them to the contact if one is defined. Is there a better way to achieve this? It seems a bit hacky!

add_hook('TicketClose', 1, function($vars) {
    Tools::sendTicketEmail($vars,'closed');
});

function sendTicketEmail($vars, $type) {

    // Get the required data
    $headertt = file_get_contents('<Removed>/headerCustom.tpl');
    $footertt = file_get_contents('<Removed>/footerCustom.tpl');
    $ticket_details = Capsule::table('tbltickets')->where('id', $vars['ticketid'])->first();
    $department_details = Capsule::table('tblticketdepartments')->where('id',   $ticket_details->did)->first();
    $emailsURL = '<Removed>/viewticket.php?tid=' . $ticket_details->tid .'&c=' . $ticket_details->c;
    $headertt = str_replace('{$emailsURL}', $emailsURL , $headertt);

    // Create a new PHPMailer object
    $mail = new PHPMailer(TRUE);                        // Set TRUE to enable exceptions
    $mail->IsSMTP();                                    // Set mailer to use SMTP
    $mail->Host = 'smtp.office365.com';                 // Specify main and backup server
    $mail->Port = 587;                                  // Set the SMTP port
...

The second problem i am having with this is when i am calling it from my modules Hooks.php, My SendTicketEmail function wont work unless it is in the hooks.php file. I have tried adding it to my tools class, which has other methods in it that call fine, but it cant seem to find the PHPMailer class? I have tried lots of requires... statements but cant seem to get it right. What do i need to do to get a custom class access the standard WHMCS classes that seem to be available to Hooks.php?

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