Adding the post author as a recipient

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 the email address of the author 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
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function my_add_post_author_email($mailer, $form, $attachments)
{
    $postId = $_POST['post_id'];
    $post = get_post($postId);
    $author = get_user_by('id', $post->post_author);    
 
    if (!empty($author->user_email)) {
        // (Optional) remove existing recipients set in the form builder
        $mailer->clearAddresses();
 
        // Add the author as a recipient
        $mailer->addAddress($author->user_email);
    }
 
    return $mailer;
}
add_filter('iphorm_pre_send_notification_email_1', 'my_add_post_author_email', 10, 3);
function my_add_post_author_email($mailer, $form, $attachments)
{
    $postId = $_POST['post_id'];
    $post = get_post($postId);
    $author = get_user_by('id', $post->post_author);    

    if (!empty($author->user_email)) {
        // (Optional) remove existing recipients set in the form builder
        $mailer->clearAddresses();

        // Add the author as a recipient
        $mailer->addAddress($author->user_email);
    }

    return $mailer;
}
add_filter('iphorm_pre_send_notification_email_1', 'my_add_post_author_email', 10, 3);
  • On line 17 replace the number 1 with the form ID

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

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