PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Sending form to author of post

  1. wimmera
    Member

    Is it possible to have the content of the form delivered to the author of the WP post? I want to use this plugin to create a "Reply to Author" form for each post on my site and am not clear from the documentation that this is possible. I want the To field populated on the fly from the post_author field without creating custom forms or using a dropdown for each author. Is this possible? Thanks.

    Posted 15 years ago on Thursday December 24, 2009 | Permalink
  2. This is possible but you need to use an API hook to filter the notification email and dynamically tell it where it should go. We would be glad to help you by pointing you in the right direction and/or providing a code snippet that can help you accomplish this.

    It would require adding some PHP code to your theme that overrides the notification email settings and tells Gravity Forms where you want the notification sent.

    Posted 15 years ago on Thursday December 24, 2009 | Permalink
  3. Jan Egbert
    Member

    This is what I did:

    add_filter( 'gform_notification_email_2', 'route_notification', 10, 2 );
    function route_notification($email_to, $entry) {
    	global $post;
    	$email_to = get_the_author_email();
    	return $email_to;
    }

    The 2 in gform_notification_email_2 represents the form ID. So you need to adjust this in order to filter the right form.

    To pre-populate the Subject field, add this:

    add_filter('gform_field_value_reactionsubject', 'populate_reactionsubject');
    function populate_reactionsubject() {
    global $post;
    return 'Reaction to ' . $post->post_title;
    }

    To pre-populate the email field:

    add_filter( 'gform_field_value_email_2', 'populate_email' );
    function populate_email(){
    if ( is_user_logged_in() ) {
     global $userdata;
    	return $userdata->user_email;
    }
    }
    Posted 14 years ago on Saturday December 26, 2009 | Permalink
  4. Nice Jan! Great to see users putting the hooks to use.

    Posted 14 years ago on Saturday December 26, 2009 | Permalink
  5. supportblog
    Member

    That's great, but if I just want to use an email address stored in a custom field, how would I accomplish that?

    Posted 14 years ago on Thursday July 1, 2010 | Permalink
  6. You look at where the code sets the value of the email to the post author. For example the first code snippet in the post above sets the notification email to address using a hook. There is a line in that code snippet that looks like this:

    $email_to = get_the_author_email();

    You would change it so that instead of equaling the get_the_author_email(); function you would set it to equal the custom field value. So it would look something like this (this isn't exact as your custom field key may be different, etc.):

    $email_to = get_post_meta($post->ID, 'CUSTOMFIELDKEY', true);

    The code would have to go in your theme template file within your loop that outputs the post so you could output the custom field value.

    Now again, my example above isn't the complete code snippet it is just an example of one line from the code snippets above.

    Posted 14 years ago on Thursday July 1, 2010 | Permalink
  7. I've tried this, but am not getting anywhere with it, I don't receive an email.

    Is there something else I need to do?

    I've added the following code to my functions.php file:

    add_filter( 'gform_notification_email_1', 'route_notification', 10, 2 );
    function route_notification($email_to, $entry) {
    	global $post;
    	$email_to = get_the_author_email();
    	return $email_to;
    }

    The URL is:
    http://joblisting.wp3.co/uncategorized/test-post

    Ignore the form in the sidebar, this was a test. It is the form on the main page.

    Thanks,

    Joe

    Posted 14 years ago on Wednesday September 8, 2010 | Permalink
  8. maarten
    Member

    Hi,

    Got the same problem. Don't know anything about php or coding, thats why I bought your plugin.

    Just want to be able to select somewhere author-email instead of a fixed admin email and it goes straight to the author.

    How can I get that?

    Thanks

    Posted 14 years ago on Tuesday September 28, 2010 | Permalink
  9. @maarten the only way to send the email to the author of a post is via a hook and with some custom PHP code. Otherwise Gravity Forms doesn't know the author of the post, which is why you have to use code to tell it the authors email.

    If you need help with this customization I can refer you to a WordPress consultant with Gravity Forms development experience who could assist you.

    Posted 14 years ago on Tuesday September 28, 2010 | Permalink
  10. maarten
    Member

    ok thanks

    Posted 14 years ago on Tuesday September 28, 2010 | Permalink
  11. I want to do something similar but instead of using a Custom Field or the Author email, to have the notification email grabbed from the url. Therefore if the url is:

    http://example.com/?jobemail=test@test.com

    then it would send the notification to the test@test.com. The reason is that my form sits on the same page all the time and is used for a number of jobs (posts). Therefore the author would always be the same.

    Any help would be appreciated.

    Posted 14 years ago on Thursday November 18, 2010 | Permalink
  12. You would do the same as the above code only you'd set the $email_to value equal to the jobemail query string value using PHP.

    Posted 14 years ago on Thursday November 18, 2010 | Permalink
  13. Yes - thanks Carl just managed to figure this one out! Use the same example above except change:

    $email_to = get_the_author_email();

    to

    $email_to = $_GET["job_email"];

    where job_email is the email part of your query string.

    Posted 14 years ago on Thursday November 18, 2010 | Permalink
  14. I thought my question would be relevant to this post. I'm utilizing the GF_THEME_IMPORT_FILE to create forms automatically on each of the sites I create in my Wordpress MS install. However, I'm also trying to dynamically load the owner of each site's email into the form. I have forgone that part of the code to just get the base to work which is filtering all Gravity Forms to send a notification to a single email address. This is my code:

    add_filter( 'gform_notification_email', 'route_notification', 10, 2 );
    function route_notification($email_to, $entry) {
    	$email_to = 'email@address.com';
    	return $email_to;
    }

    I can't imagine this being any simpler, but it's not working. Do I still need to set the notifications in the back end to a random email address then this will change it? How do I make this work?

    Posted 13 years ago on Wednesday February 16, 2011 | Permalink
  15. @mymodernweb Is there any reason you are trying to do this with code instead of allowing them to configure their notifications? I ask because if you implement this code to set the sent to address using PHP it's going to override any settings they make in the Notifications configuration which could be very confusing to the admin of that site. This would override their settings.

    Posted 13 years ago on Wednesday February 16, 2011 | Permalink
  16. @Carl yes...I do not want them to manage on the back end. In fact, they don't even have access to it on the back end. So, the idea is I'm actually going to pull in dynamically their email address they fill in on their user profile and that will be the email address it uses by default. If they want to change where all their contact information is going to they have to change their user profile information is the plan.

    Nonetheless, when I create a form and submit it nothing is being sent to the email address I declare here. I am declaring it just the way I posted above. I have not even inserted the code to dynamically pull in the site owners email address. Do I need to also set with the filter the subject and a body maybe for it to work?

    Posted 13 years ago on Wednesday February 16, 2011 | Permalink
  17. @mymodernweb I just tested this functionality on a test site using this code:

    <?php
    add_filter("gform_notification_email", "change_notification_email", 10, 2);
    function change_notification_email($email, $form){
       return "my@email.com";
    }
    ?>

    Only I used a real email address instead of my@email.com and this code works fine for setting the admin notification send to email using code. The code above did what I expected to.

    I would suggest trying the code above which is slightly different than what you are using.

    Please keep in mind that an Admin Notification has to be configured and setup in order for this to work. If no Admin Notification is configured for that form then setting this email address isn't going to matter because no Notification will be sent if one isn't configured in the form notification settings.

    Also keep in mind this hook is for the Admin Notification. There is a different hook for setting the Send To on the User Notification.

    Posted 13 years ago on Wednesday February 16, 2011 | Permalink
  18. I believe it was just that I didn't have it configured properly on the backend. Thank you for the help. I have it working now.

    Posted 13 years ago on Wednesday February 16, 2011 | Permalink
  19. @mymodernweb Good to hear, glad you got it working! It's good to see people using Gravity Forms in creative ways.

    Posted 13 years ago on Wednesday February 16, 2011 | Permalink
  20. Ok I will attempt to repost this. I believe it just got lost.

    I have tried this code:

    add_filter( 'gform_notification_email_4', 'route_notification', 10, 2 );
    function route_notification($email_to, $entry) {
    	global $post;
    	$email_to = get_the_author_email();
    	return $email_to;
    }

    On a new situation where I'm trying to send Form ID 4 to the email of a custom post type's author. However, it is not working for any reason. Am I missing something in the code?

    Posted 13 years ago on Friday April 29, 2011 | Permalink
  21. Hi mymodernweb,

    Try setting your $email_to variable like this:

    [php]
    $email_to = get_the_author_meta('email', $post->post_author);

    Bear in mind, this will send the email to the author of the post/page from which the Gravity Form was submitted.

    Posted 13 years ago on Friday April 29, 2011 | Permalink
  22. Works great, but I need the email to be sent to the administrator of the website aswell!

    http://www.pastie.org/1864422
    'email_verkoper' is an emailaddress in a custom field.
    This email is sent, and the user gets a copy. But, the BCC fields in Gravity Forms aren't working. No BCC is sent. How otherwise can I have a third email sent to the owner of the website?

    Posted 13 years ago on Wednesday May 4, 2011 | Permalink
  23. Are you using a separate email account for testing the BCC? I just checked on my end and the BCC email is being sent without issue.

    Posted 13 years ago on Wednesday May 4, 2011 | Permalink
  24. Hi David,

    Sorry didn't see you answered... notification email wasn't sent :-(

    Yes I tried a different email. Tried multiple combination's and emailadresses. To be sure it wasn't a spamfilter stopping emails coming through or issues with the same domainname etc...

    BCC without the changes works... but with the changes it doesn't. Bit in a bother cause deadline is running fast towards me with huge big teeth... Hope you can help!

    Posted 13 years ago on Tuesday May 10, 2011 | Permalink
  25. @Cold Coffee I'm not sure what you mean by "BCC without the changes works..." can you clarify what you mean "without the changes" because the changes above aren't for the BCC field, they are for the Send To field.

    Posted 13 years ago on Tuesday May 10, 2011 | Permalink
  26. Without the extra code for using the custom field in functions.php
    Sorry.

    Posted 13 years ago on Tuesday May 10, 2011 | Permalink
  27. Try this instead then...

    - Add an Email field to your form
    - Select the Advanced tab and set the visibility to Admin Only
    - Allow the field to be populated dynamically
    - Use PHP and the pre-population hook to pre-populate this email field value with the user meta email value for the author.

    Once you do that you'll now have an email field on your form that is being populated with the authors email address and saved as part of the entry.

    Now on the Notification, configure the Send To for the Admin Notification to go to this field using it's field merge code/variable. You can get this by using the "Insert form field" to insert it into the Message Body and then copy-n-paste it into the Send To address. Then setup your BCC field as normal.

    This is another way to do what you are trying to do.

    Posted 13 years ago on Tuesday May 10, 2011 | Permalink
  28. Okay thnx, will try this tomorrow. Not trying to send to the author though... but to an email that is set in a customfield... but I understand you and will try. Great! I'll let you know what the outcome is!

    Posted 13 years ago on Tuesday May 10, 2011 | Permalink
  29. Carl - I like that method a lot more because it involves less code (haha), but I don't understand what to paste into the "parameter name" field from your instructions below...

    - Use PHP and the pre-population hook to pre-populate this email field value with the user meta email value for the author.

    I just want to know what to put that will populate that field with the current post's author email.

    Posted 13 years ago on Wednesday May 11, 2011 | Permalink
  30. Hi, problem not solved. Cause I need 3 emails to be sent.
    1. to the form submitter
    2. to the emailadres populated in the custom field 'email_verkoper'
    3. a copy of either emails to the owner of the website

    The script addition in functions.php works great, but then the BCC field bugs it up. No emails are sent. The second solution given, doesn't fit the needs cause then the formsubmitter doesn't get an email. I tried putting the field code (ex {E-mailadres:3}) in the emailfields, but that doesn't work.

    And now I have a second problem. The emailtemplate for the user notification doesn't work (didn't edit it so why it's broken no idea). I deleted it and put it back, but nothing works. Even emptied it and just put ' test' in it, but it ignores that.

    Could somebody at Gravity forms please help? I can send the address (ip address and domain for in the hosts file, cause site isn't live yet) and I am willing to pay for the help.

    info@coldcoffee.nl

    Posted 13 years ago on Thursday May 12, 2011 | Permalink
  31. Okay idea... is there a way to add in that piece of script a BCC emailaddress? This is an emailaddress that wont change... so could be hardcoded. Getting really desperate now :-(

    Posted 13 years ago on Thursday May 12, 2011 | Permalink
  32. You can configure a hardcoded BCC field in the Notifications settings for that form. BCC is a field you can enter an email address in. You don't need to use PHP code if the BCC email address isn't going to be dynamic.

    Posted 13 years ago on Thursday May 12, 2011 | Permalink
  33. For anyone looking for more information on dynamic population with Gravity Forms, be sure to check out these two new documentation articles:

    Using Dynamic Population
    Dynamically Populating the Post Author

    Posted 13 years ago on Thursday May 12, 2011 | Permalink
  34. @Carl: thnx but that is the problem. When I fill in an emailaddress in the BCC field, the form stops working and doesn't send any email. That's why I would love to see an addition to the extra script with a hardcoded BCC.

    I know it should work, but it doesn't. After hours unpaid work for trying to solve this I'm risking missing the deadline and even more unpaid hours. So I would love just a small addition to the script (see my first post) where I can hardcode the BCC email.

    Posted 13 years ago on Friday May 13, 2011 | Permalink
  35. @Cold Coffee I don't think I quite understand what you mean by hardcode the BCC email. You can hardcode the BCC email by entering it in the Notification sendings. If you can provide more clarification it would be helpful because I think the terminology you are using is probably causing me not to understand what you are referring to. Adding the BCC email in the Notification settings for that form is hardcoding it.

    Posted 13 years ago on Friday May 13, 2011 | Permalink
  36. @Carl and that doesn't work. Putting an email in the notification settings does not work. No emails are sent (must be because of the script I'm using: http://www.pastie.org/1864422). What I mean by hardcoding is: forcing it to work by putting the BCC emailaddress in the template file, GF file or functions.php.

    Posted 13 years ago on Saturday May 14, 2011 | Permalink
  37. Anonymous
    Unregistered

    I just recently tried this to send emails to people based off of the email they submitted in a custom meta box i created using Advanced Custom Fields. I worked perfectly unfortunately it made it so no one could submit or update a post.
    Here is the code I used:

    add_filter( 'gform_notification_email_12', 'route_notification', 10, 2 );
    function route_notification($email_to, $entry) {
    	global $post;
    	$email_to = get_field('VEmail');
    	return $email_to;
    }

    We are running WordPress 3.2.1. with Genesis Lifestyle Child Theme.

    Has any one run into this or did i just jack my code up?

    Posted 13 years ago on Wednesday November 23, 2011 | Permalink
  38. Hi Snap,

    Looking at your code, I don't see why this would prevent the submission or updating of posts? If you comment out this code are you able to submit and update posts once more?

    Posted 13 years ago on Wednesday November 23, 2011 | Permalink
  39. Anonymous
    Unregistered

    Removing it fixed the problem.

    We ended up with this havn't had any problem so far but we are still watching it.

    add_filter("gform_notification_email_12", "change_notification_email", 10, 2);
    function change_notification_email($email, $form){
        $email =get_field('VEmail');
        return $email;
    }
    Posted 13 years ago on Monday November 28, 2011 | Permalink
  40. I am going to close this topic as it is in the pre-purchase section and we try not to provide support here. If any members have questions about the code here, please feel free to start a new topic in the regular support forums and reference this topic.

    Posted 13 years ago on Thursday December 1, 2011 | Permalink

This topic has been resolved and has been closed to new replies.