Adding a recipient from a custom field

This documentation page is for Quform version 1 and may not be applicable for Quform 2 click here to visit the documentation for Quform 2.

This guide will show you how to add an email address from a custom field of the post containing the form as a recipient of the notification email. Add the following code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it).

1
2
3
45
6
7
8
9
10
11
12
13
14
15
16
function my_custom_form_recipient($mailer, $form, $attachments)
{
    $postId = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
    $email = get_post_meta($postId, 'my_custom_email_field', true); 
    if (is_string($email) && $mailer->validateAddress($email)) {
        // Remove existing recipients set in the form builder
        $mailer->clearAddresses();
 
        // Add the custom field email as the recipient
        $mailer->addAddress($email);
    }
 
    return $mailer;
}
add_filter('iphorm_pre_send_notification_email_1', 'my_custom_form_recipient', 10, 3);
function my_custom_form_recipient($mailer, $form, $attachments)
{
    $postId = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
    $email = get_post_meta($postId, 'my_custom_email_field', true);

    if (is_string($email) && $mailer->validateAddress($email)) {
        // Remove existing recipients set in the form builder
        $mailer->clearAddresses();

        // Add the custom field email as the recipient
        $mailer->addAddress($email);
    }

    return $mailer;
}
add_filter('iphorm_pre_send_notification_email_1', 'my_custom_form_recipient', 10, 3);
  • On line 4 replace my_custom_email_field with the name of the custom field
  • On line 16 replace the number 1 with the form ID

If you do not want the recipients from the form builder removed, remove line 8.

Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy