DennisHermannsen Posted October 23, 2020 Share Posted October 23, 2020 I need to be able to send the customer a unique token through WHMCS. I've created the email template and am sending the email using the SendEmail API. The only issue is that the email appears in the Email History - and that means that the unique code can be seen by anyone with access to the account (not great in case the account is compromised). I used to just manually add the email template to the 'user' category, but some recent update has made it impossible to send any emails from that category even though the response says success. Does anyone know of a way to send emails that won't be saved in WHMCS? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 23, 2020 Share Posted October 23, 2020 3 minutes ago, DennisHermannsen said: Does anyone know of a way to send emails that won't be saved in WHMCS? how about using the EmailPreLog hook point to abort logging when the email is sent ? Quote Runs prior to email being logged. Accepts a return of key/value pairs to override the parameters to be logged. Use the same names as the input parameters. Return abortLogging to abort logging of the email. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted October 23, 2020 Author Share Posted October 23, 2020 8 minutes ago, brian! said: how about using the EmailPreLog hook point to abort logging when the email is sent ? That could have worked if I was able to filter them based on message name, and not just the subject. The subject is not always the same 😅 Any other ideas? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 23, 2020 Share Posted October 23, 2020 4 minutes ago, DennisHermannsen said: Any other ideas? you awkward .... 🤪 is there content of the message that you can filter on, e.g a specific string or sentence that will be used only in this email, that you don't use elsewhere in other templates ? 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted October 23, 2020 Author Share Posted October 23, 2020 (edited) 14 minutes ago, brian! said: is there content of the message that you can filter on, e.g a specific string or sentence that will be used only in this email, that you don't use elsewhere in other templates ? I don't actually think it matters... It doesn't seem like the EmailPreLog hook is triggered when you use the SendEmail API 😂 Have you used it before with the API? Edit: Wait, does anything ever trigger it? I just tried with this code: <?php //Do not log emails for userid 2 add_hook('EmailPreLog', 1, function($vars) { $return = []; if ($vars['userid'] == 4) { $return['abortLogging'] = true; } return $return; }); My user ID is 4 - it still logs it. No matter if I send it using the API or send one of the default emails. The exact same code works for v7 - just not v8 🧐 Edited October 23, 2020 by DennisHermannsen 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 23, 2020 Share Posted October 23, 2020 27 minutes ago, DennisHermannsen said: Have you used it before with the API? I don't think so....only with default templates. if the concern is the email being seen in the client area, then you could use a ClientAreaPageEmails hook and remove those messages from the array... if it's more that no one sees it in the admin area, then you'd probably have to query the db and remove it from the table. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted October 23, 2020 Author Share Posted October 23, 2020 I'm stoopid, I forgot a semicolon 😂 The following works, but it's probably not pretty to access the database on every email sent... <?php add_hook('EmailPreLog', 1, function($vars) { $templates = Capsule::table('tblemailtemplates') ->select('subject') ->where('name', '<Template Name>') ->get(); $return = []; foreach($templates as $names){ LogActivity($names->subject); if($names->subject === $vars['subject']) { $return['abortLogging'] = true; } } return $return; }); 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.