Jump to content

Having trouble with SendEmail localAPI request


Recommended Posts

RESOLVED: It did not like the 'customtype' defined in the postdata, give I supplied an existing template (I suppose). Remarking that out resolved (updated below).

This is the code I have in place. It is triggering after AfterModuleTerminate, but not sending email and logging activity.
In the logactivity result, the values for $serviceid and $clientid are showing anticipated values.

I am trying another pass with 'customtype' => 'product',  remarked out.

Any ideas. I only recently added the $adminUsername to see if it would resolve but same issue. We are on 8.13.1.
 

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

function send_termination_notice($vars) 
{
	try {
		$serviceid = $vars['params']['serviceid'];
		$emailtemplate = 'Service Termination Notification';
		$clientid = $vars['params']['userid'];
		$command = 'SendEmail';
		$postData = array(
			
			'messagename' => $emailtemplate,
			'id' => $serviceid,
			//'customtype' => 'product',// functions properly with this parameter remarked out
		);
		
		$adminUsername = 'admin.usersample'; // Optional for WHMCS 7.2 and later
	
		$results = localAPI($command, $postData, $adminUsername); 
		if ($results['result'] != 'success') {
				logActivity('Termination Notice failed to send for serviceid ' . $serviceid . ' for clientid ' . $clientid . ' by hook send_terminatio_notice...');
		}
	}
	catch (\Exception $e) {
		logActivity("Termination notice failed: {$e->getMessage()}");		
	}
}

add_hook('AfterModuleTerminate', 1,'send_termination_notice');

 

Edited by TBroMEM
Noting Resolution
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