Adding the post author as a recipient

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.

Still having trouble? Head over to the forums.

Forums