Jump to content

Prevent Proforma Invoice Emails being sent to certain clients


craigedmonds

Recommended Posts

I am working on a hook using EmailPreSend to prevent proforma invoice emails being sent to the client. (what we do is on the first of each month, for some clients, we merge all their proforma invoices into one invoice and send them the main invoice).

However, I am stuck on understanding the var for "messagename". Really the API docs do not explain it very well at all.

What would the message name be for $vars['messagename'] ??

Any ideas folks?

<?php
/*
see: https://developers.whmcs.com/hooks-reference/everything-else/#emailpresend
*/

//prevent someone accessing this file directly
if (!defined("WHMCS")) die("This file cannot be accessed directly");
	
add_hook('EmailPreSend', 1, function($vars) {

	//if this is the proforma invoice about to be sent we need to check if there
	//is any clients we DONT want to send proforma emails to
	if ($vars['messagename'] == 'My Message Name') {
	
		//this will be the proforma invoice number
		$relid = $vars['relid'];
		
		//list of client id's I DO NOT want to send proforma emails to
		$clients = array(
		"111",
		"222",
		);
	
		//need to get the clientid from $relid
		$sql = "SELECT userid FROM tblinvoices WHERE id = $relid";
		$result = full_query($sql);
		$data = @mysql_fetch_array ($result);
		$userid = $data['userid'];
		
		//check if userid is to NOT receive proforma emails
		if(in_array($userid, $clients)){
	   		$merge_fields['abortsend'] = true;
			return;
	 	}

    }

});

//end of hook
?>

 

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