Replies: 2
Hello there, using the free version.
How can I create a hook to send a custom email? The idea is that I can control some of the values, calculate numbers and so on, before i send.
Yes I can use the calculation items inside of the plugin, but eventually the code will have to check versus arrays and build replies based on the calculations. Calculations in the plugin are limited.
Whatever I try and google, nothing works, so I ask here.
1. The hook must be able to grab data from the email that is submitted.
2. I will have to perform my calculations.
3. The hook must be able to send to the customer a specific email with some info.
4. The hook must send the submitted info to the admin
I have found this, but it does not work.
add_action( 'forminator_form_after_save_entry', 'my_form_submit', 10, 2 );
function my_form_submit( $form_id, $response ) {
if ( $response && is_array( $response ) ) {
if ( $response['success'] ) {
if ( $form_id == 6 ) {
// Code goes in here
}
}
}
}
I had transformed it into —
add_action('forminator_form_after_save_entry', 'function_Name', 10, 2);
function function_Name($form_id, $response)
{
if (isset($response['success']) && $response['success']) {
// Log the form submission data
error_log('Form submission data: ' . print_r($response, true));
// Test wp_mail function
test_wp_mail(); // Make sure this is your function to test sending emails
}
}
// A basic test wp_mail function to ensure it's working
function test_wp_mail()
{
$to = 'myemail@mydomain.com'; // Updated email for testing
$subject = 'Test email from wp_mail';
$message = 'This is a test email to check if wp_mail is working.';
$headers = array('Content-Type: text/plain; charset=UTF-8');
$mail_sent = wp_mail($to, $subject, $message, $headers);
// Log the result of wp_mail
if ($mail_sent) {
error_log('Test email sent successfully!');
} else {
error_log('Test email failed to send.');
}
}
Thanks for your help!