Runs before main mailer sends an email. The variable
The variable $data has all entry data that can be used in the email.
Note: In Caldera Forms 1.3.5 and later, if this filter does not return an array, it aborts sending the email. This makes this an excellent hooks for two uses:
- Sending mail data to an alternative email service to avoid phpmailer.
- Using this hook for easy access to entry data to do something besides send an email.
This filter exposes 4 parameters:
- $mail The configuration for the email
- $data The form entry data as an array
- $form The form configuration
- $entryid The entry ID — added in Caldera Forms 22.214.171.124
This example below shows how to add an extra recipient to the email:
With the example above, you may wish to empty the ‘recipients’ index first. Even if you set no recipients in the email notification tab, the fallback address — admin email — will have been added.
This example shows how to customize the email message from the mailer tab:
In this next example, a Caldera Form field value is written to a file and then attached to the email. This illustrates both how to copy a field value to file, as well as how to add attachments to the Caldera Forms Email.
Using A Custom HTML Template For Caldera Forms Email
Where Does This Code Go?
When using WordPress hooks to customize Caldera Forms or other plugins you should not modify the plugin files, or you will lose your changes when you update the plugin. Instead you should create a small plugin to hold the custom code. It's easy, learn how here.
Technically you can add the custom code to your theme's functions.php, but then you will not be able to change your theme and keep these customizations.