Notify User When Submitted Post is Published

January 31, 2020: Fixed issue where email was not sent due to formatting issue in code.

This handy snippet allows you to send an email notification to the user who submitted a Gravity Forms generated post when that post is published.

This snippet assumes you have created a Post Custom Field which will store the submitting user’s email address. You would then specify the “Custom Field Name” you specified for the field as the $custom_field_name variable.

For example, assuming I had configured a Post Custom Field with the following settings:

Sample Post Custom Field settings configured as an email field

I would set the $custom_field_name variable like so:

$custom_field_name = 'author_email';

Lastly, don’t forget to set your basic email settings!

$from_name  = 'Your Name';
$from_email = 'your@email.com';
$subject    = 'Your Subject Here';
$message    = 'Your message here.';

This will only work for regular WordPress posts. If you’d like to apply to pages (or any custom post type), you’ll want to update the action from “publishpost” to “publish{your_post_type}”.

Comments

    1. David Smith
      David Smith Staff December 12, 2017 at 7:57 am

      No, it will send the email to whatever email address is saved in the “author_email” custom field.

  1. Vahid
    Vahid May 13, 2016 at 1:55 am

    Hi David.

    This snippet is not working and cause 500 error on my website.. I already added your snippets in functions.php and I add this code to theme functions.php too.

    Regards, Vahid.

    Reply
    1. David Smith
      David Smith Staff October 23, 2015 at 8:19 am

      Hi Jeph, you can include HTML in the message like so:

      $message = '

      Hello!

      This is a message.

      ';

      You can include a link to the post like so:

      $message = 'View your post here: View Post';

    2. Jeph
      Jeph October 26, 2015 at 11:05 am

      Thanks David! I’ve been trying to play around adding other custom fields from the form, but I can’t quite figure it out? How would I include the post title and another field from the form?

    3. David Smith
      David Smith Staff October 26, 2015 at 9:05 pm

      You can get the post title like so:

      $post_title = get_the_title( $post_id );

      The entry bit is more complicated.

      $entry = GFAPI::get_entry( get_post_meta( $post_id, '_gform-entry-id', true ) ); $my_value = $entry[3];

      Replace the “3” with the field ID you want to retrieve the data from.

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Download Snippet

Notify User When Submitted Post is Published

This field is for validation purposes and should be left unchanged.