• Resolved vi54

    (@vi54)


    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 = '[email protected]'; // 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!

    • This topic was modified 1 year, 3 months ago by vi54.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @vi54

    Hope you are doing well today.

    If you want to edit the form email you can use forminator_custom_form_mail_before_send_mail hook, and if you want to send a different custom email you should look for send_email function in this file /forminator/library/modules/custom-forms/front/front-action.php file.

    Since custom coding is out of scope of our support if you need further assistance, you’ll need to hire a developer to provide the required custom code for you. WordPress provides a jobs directory here https://jobs.wordpress.net/, if you need further advice about it, feel free to email [email protected].

    Subject: ATTN: WPMU DEV support – wp.org

    Kind Regards
    Amin

    Thread Starter vi54

    (@vi54)

    That is perfect Amin!

    Amazing that I did not spot that ook!
    It works perfectly.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Run custom code when form submit’ is closed to new replies.