WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
[resolved] Mail Recipient always different (10 posts)

  1. wacwac
    Member
    Posted 3 years ago #

    Hi,
    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?

    Thanks

  2. phycel
    Member
    Posted 3 years ago #

    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 - http://contactform7.com/2009/12/25/special-mail-tags/

    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!

  3. wacwac
    Member
    Posted 3 years ago #

    Thank you very much!!!

    You have solved my problem!

  4. phycel
    Member
    Posted 3 years ago #

    Glad I could help. :)

  5. BAC
    Member
    Posted 3 years ago #

    @phycel

    '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.

    BAC

  6. BAC
    Member
    Posted 3 years ago #

    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.

  7. BAC
    Member
    Posted 3 years ago #

    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' );
    }
  8. xdp_qbx
    Member
    Posted 3 years ago #

    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:
    Subject:
    Message:

    is this possible?

    thanks if someone could help me this...

  9. lallusarpanch
    Member
    Posted 3 years ago #

    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
    thanks

  10. lallusarpanch
    Member
    Posted 3 years ago #

    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
    thanks

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic