I was looking to do something similar, and came up with an answer that might be useful to someone.
1. It assumes that the desired recipient email is a custom field on the post - example assumes this custom field is called 'recip_email'.
2. When setting up the form add a hidden field, populated with the variable {embed_post:ID} - example assumes this is FieldID 5 in form 10.
3. Add a recipient email field, set visibility to admin only. Example assume this is Field ID 7
4. Enable notification to users, select the recipient email address as the to address.
5. Add this function
add_action("gform_pre_submission_10", "get_the_recipient_email");
function get_the_recipient_email($form){
$recip_mail=get_post_meta($_POST["input_5"],'recip_email', true);
$_POST["input_7"] = $recip_mail;
}
Because you are doing this post submission the recipient email is not visible in the source at the time the form is submitted, but is added before the email is sent.
Added - in fact you could do this by entering a custom field value as a variable in the recipient email field directly. I actually did something else - which was to get the post author email, which was not stored as a custom field. That looked like this:
add_action("gform_pre_submission_10", "get_the_business_recipient");
function get_the_business_recipient($form){
$post_id = get_post($_POST["input_5"]);
$author=get_userdata($post_id->post_author);
$_POST["input_7"] = $author->user_email;
}
Posted 12 years ago on Monday May 28, 2012 |
Permalink