Jump to content

Send emails that won't appear in Email History


Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by DennisHermannsen
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
});

 

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