You can’t use ‘bricksforge_send_mail’ in a custom action unless you’re an authorised user with editor rights. I had to look up the source code to solve this.
A workaround is to prefix the template_id to the message and use wp_mail.
$message = "###BRFTEMPLATEID:{$template_id}###" . $message;
if ( wp_mail( $to, $subject, $message )){
$form -> set_result(['action' => 'SendEmailPlease', 'type' => 'success', 'message' => esc_html__("Holy smoke captain. It damn well sent!", 'bricks')]);
return;
}
Another workaround is to set BRICKSFORGE_ALLOW_UNAUTHENTICATED_AJAX_EMAILS global variable. Not recommended.
The function is shared with Ajax so unauthorised users are rightly blocked, but this also blocks non Ajax calls from custom actions.
My custom template was utilised by the Email action and by ‘wp_mail’ if I set the condition to All forms. I went round and round in circles for a few days on this one.
Edit: I’ve since realised a custom action is Ajax under the hood so this isn’t really a bug.