Support » Plugin: Contact Form 7 » [Plugin: Contact Form 7] Mail Recipient always different

  • Resolved wacwac


    I would like put in a variable the recipient of mail.
    I try to explain:
    in the post01 I want send email to person01, in the post02 I want send email to person02, in the post03 I want send the email to person03, etc…
    I don’t want to create a contact form for each recipient(person01, person02, person03,…) because I have many recipient (about 200).
    Can I put the recipient in a variable and then set the variable in the post? How can I do?


Viewing 9 replies - 1 through 9 (of 9 total)
  • It depends on how your posts or pages are set up. Are these user profile pages? If so, you may be able to use one of the pre-written special mail tags. There is one available for the post-author email. So, on the form settings page in the Mail TO: field put [_post_author_email] and as long as each post or page is for that specific user, then it should send it to that user’s email. Here are all the special mail tags built into the plugin –

    If these aren’t user profiles and the posts or pages aren’t created by different authors, then you’ve got just a little bit of custom coding to do. My first step would be to see if I can utilize custom fields for the recipient email address.

    Try this…

    In /wp-content/plugins/contact-form-7/modules/special-mail-tags.php add this line of code just before the return $output on line 69:

    elseif ( '_post_recipient' == $name )
    	$output = get_post_meta($post->ID, 'recipient', true);

    Then go to one of your posts where you will have these custom forms and add a custom field with the name “recipient” and enter the recipient’s email for the value.

    Lastly, go to your form settings that is inserted within your post and add [_post_recipient] in the TO field.

    Now test it and see if it will work. Doing it this way will allow you to use only one form for all 200 posts, but you will need to specify the recipient email in the custom fields of each post.

    Good Luck!

    Thank you very much!!!

    You have solved my problem!

    Glad I could help. 🙂


    ‘elseif ( ‘_post_recipient’ == $name )
    $output = get_post_meta($post->ID, ‘recipient’, true);’

    Thanks so much for this! solved a headache 🙂

    One issue I need to address is when the plugin is updated these changes will be lost. Can this code be applied via a filter in functions PHP or a separate plugin so that the plugin can be updated (being a form plugin security is a concern)

    Thanks so much.


    Just in case anyone finds this titbit useful, I had issues with the contact form 7 failing when the form was placed outside the post wrapper div for some reason. I tried initialising the form via the php hook just before closing body tag as I wanted the form to pop up via a modal window but this failed for some reason. Adding the form within the post content worked just fine with this hack.

    I got this far creating a filter in functions to survive a plugin update but it doesn’t seem to want to work.. 🙁

    Would very much appreciate some assistance!

    function customFieldEmailTag( $form_tag )
    	if ( $form_tag['name'] == '_post_recipient' ) {
    		$form_tag = get_post_meta($post->ID, 'job:apply', true);
    	return $form_tag;
    if ( !is_admin() ) {
            add_filter( 'wpcf7_form_tag', 'customFieldEmailTag' );

    hi, how can i get the post title to appear in the form? like for example

    John Doe is the title of the post, then when the user clicks the send an email link in John Doe’s profile, it will then go the the contact form page using contact form 7 and i want my form to be like this:

    Recipient: John Doe
    Your name:
    Your Email:

    is this possible?

    thanks if someone could help me this…

    hi, please help me i am new in wordpress

    i want that if user mail me via contact form a copy of that form also go back to him or his email address..

    please reply me soon

    hi i am using custom contact form plugin

    now i want that if user mail me via contact form then a copy of that email go back to user

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: Contact Form 7] Mail Recipient always different’ is closed to new replies.