Calling the Function
By the time you get here, your job is basically finished. All that is left to do is to actually call the sendEmail function. And this can be done two different ways. You can either call the function as a side effect of another serverside action (for example, when a certain model is added, send a notification to admin) or it can be a direct function call (usually in this case, it will be accompanied by a button).
To send an email as a side effect of another function
This is very simple, basically within the same file, within the function in which the email should be called as a side effect, you simply call the sendEmail function as normal. This can be done in the following manner:
$this->sendEmail($params);
Send email directly
For this you should be using a direct ajax request, and there is a detailed guide on how to set up an ajax request here (this shows the client side only, this will be changed to a full guide on direct requests later). So we will not demonstrate with this specific example in this guide.
Full Integrated Example
In our integrated example, it could conceivably be called either way. It could happen that we have a list of cars in this insurance company, and within the table, we have a button which says "total car" or it could be when adding a "crash report" it sends the car total email as a side effect. For the sake of simplicity in demonstration, we will be using the latter scenario.
public function add($object) {
$this->auth();
// ...previous code
//recipients is fetched earlier in this function.
$this->sendTestEmail($recipients, $object['name'], $object['note'], $object['color']);
// ...later code
}