• I need a little direction on this. This was the only plugin that looked like it could do what I needed, so I am grateful for that. But I’m not good with writing php. I see where the emails go, but I’m assuming from looking at it that for each I could edit the select-email to be something different and then define it in an array somewhere? Actually, no, it looks like I would have to set select-email to differentiate between 1,2,and3 with it’s own parameters…. Yep, confused, please help!

    https://wordpress.org/plugins/contact-form-7-dynamic-mail-to/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author John Huebner

    (@hube2)

    Hi,

    Can you outline what it is you’re trying to do. What you want to base where the email is sent on.

    I can also give you an example of the way I’ve used it, and actually the reason that I created this in the first place. The client wanted the emails from a form to go to different recipients depending on topic selected.

    So first I have a select field with the topics

    Topic: [select your-topic "choice 1" "choice 2" "choice 3"]

    Then I used my other plugin that creates hidden fields to create the following fields.

    [simplehidden dynamic-mail-to-filter "dynamic-to-from-topic"]
    [simplehidden dynamic-mail-to-fields "your-topic"]

    The first field is the name of the filter to apply and the second is the field name of the topic field so that the value of that field is passed to the filter.

    The next thing I did was to create the filter function that returns an email address based on the topic value selected.

    add_filter('dynamic-to-from-topic', 'dynamic_to_from_topic'), 10, 2);
    function dynamic_to_from_topic($recipient, $args=array()) {
      $topic = 'default';
      if (isset($args['your-topic'])) {
        $topic = $args['your-topic'];
      }
      $recipient = 'default@email.com';
      $recipients = array(
        'default' => 'default@email.com',
        'choice 1' => 'person1@email.com',
        'choice 2' => 'person2@email.com',
        'choice 3' => 'person3@email.com'
      );
      if (isset($recipients[$topic])) {
        $recipient = $recipients[$topic];
      }
      return $recipient;
    }

    Let me know if that helps or if I can explain further.

    Thread Starter techie.girl

    (@techiegirl-1)

    Sorry, of course. This is for a mortgage broker. There are a couple of different deciders here. It will be based on three field selections and will be sent to two different emails.

    So it will look like this:

    If A is greater than 100,000 it goes to email1, if less, it goes to email2.

    Unless B is over 20,000 or C is over 40,000 then it goes to email1 regardless.

    Make sense?

    Plugin Author John Huebner

    (@hube2)

    To use two field in my example above I would create a hidden field that looked like this.

    [simplehidden dynamic-mail-to-fields "field-name-1,field-name-2,field-name-3"]

    This will pass an array of argument to the filter function that looks something like this.

    $args = array(
      'field-name-1' => 'value of field 1',
      'field-name-2' => 'value of field 2',
      'field-name-3' => 'value of field 3'
    );

    Then you’d use those values to return the email correct email address

    add_filter('dynamic-to-from-values', 'my_dynamic_to'), 10, 2);
    function my_dynamic_to($recipient, $args=array()) {
      if ((isset($args['field-name-2']) &&
           intval($args['field-name-2'] > 20000) ||
          (isset($args['field-name-3']) &&
           intval($args['field-name-3']) > 40000) ||
          (isset($args['field-name-1']) &&
           intval($args['field-name-1) > 100000)) {
        $recipient = 'email1';
      } else {
        $recipient = 'email2';
      }
      return $recipient;
    }

    Thread Starter techie.girl

    (@techiegirl-1)

    Thanks so much. I’ll give this a shot.

    Thread Starter techie.girl

    (@techiegirl-1)

    One more question. Is the hidden form ID supposed to match the filter name? How does the hidden field call the specific filter?

    We have a couple dozen forms, and some of the field ids like income etc go across multiple forms. I don’t see a way to call different filters on a per form/hidden field basis. I’m assuming then I should go through and rename all the field ids with a per form identifier prefix or the like, or is there a way to setup multiple filters at all?

    Plugin Author John Huebner

    (@hube2)

    This field gives the name of the filter. The name of the field must be “dynamic-mail-to-filter”. The value of the field is the name of the filter hook.

    [simplehidden dynamic-mail-to-filter "dynamic-to-from-filter-hook"]

    This is the field that specifies the additional field values to pass to the filter. The name of this field must be “dynamic-mail-to-fields”. The value of this field is a comma separated list of field names.

    [simplehidden dynamic-mail-to-fields "field1,field2,field3"]

    Thread Starter techie.girl

    (@techiegirl-1)

    Duh, sorry. For some reason I was thinking, nevermind. Missed the obvious while I was trying to figure something else out. Thank you for getting back to me!

    Thread Starter techie.girl

    (@techiegirl-1)

    Ok, still having problems, even with all the hand holding. Thank you so much for all the help in advance. The instructions say to fill either the filter or the shortcode example in the examples file. I’ve dinked around with putting my filter in both slots, and I can’t get it to work. There’s no email sent, unless it’s going to the email address in the ‘mail’ tab.

    In the CF7 database, there are two additional fields showing related to the plugin that I did not name, nor can I find in the plugin files – In the four total it looks like this:

    dynamic_to_email – blank
    dynamic-mail-to-filter – dynamic-to-from-values
    dynamic_to_fields – blank
    dynamic-mail-to-fields – loan-amount,income,net-worth

    Am I supposed to be putting something in the email line under the mail tab of the form?

    Here’s my cf-mail to examples file:

    <?php 
    
    	/*
    			This file contains and example filter and an example shortcode to use with Contact Form 7 - Dynamic Mail To	You will need to edit this file to get it to work the email addresses in this file are not real email addresses (as far as I know)after changing this file to include valid email addresses follow the instructions in readme.txt for setting up either the filter or the shortcode example
    
    	*/
    
    	// If this file is called directly, abort.
    	if (!defined('WPINC')) { die; }
    
    	new wpcf7_dynamic_mail_to_examples();
    
    	class wpcf7_dynamic_mail_to_examples {
    
    		// these are the email addresses to be used to for setting the recipient email address in cf7
    		private $email_address_1 = 'email01@email.com';
    		private $email_address_2 = 'email02@email.com';
    		private $email_address_3 = 'email01@email.com,email02@email.com';
    
    		public function __construct() {
    			add_filter('wpcf7-dynamic-mail-to-example-filter', array($this, 'filter'), 10, 2);
    		} // end public function __construct
    
    		public function filter($recipient, $args=array()) {
    			//echo '(',$recipient,')';
    			//print_r($args); die;
    			if (isset($args['select-email'])) {
    				if ($args['select-email'] == 'send to email 1') {
    					$recipient = $this->email_address_1;
    				} elseif ($args['select-email'] == 'send to email 2') {
    					$recipient = $this->email_address_2;
    				} elseif ($args['select-email'] == 'sent to email 3') {
    					$recipient = $this->email_address_3;
    				}
    			}
    			return $recipient;
    		} // end public function filter
    
    	} // end class wpcf7_dynamic_mail_to_examples
    
    function my_dynamic_to($recipient, $args=array()) {
      if ((isset($args['income']) &&
           intval($args['income'] > 250000) ||
          (isset($args['net-worth']) &&
           intval($args['net-worth']) > 500000) ||
          (isset($args['loan-amount']) &&
           intval($args['loan-amount') > 1000000)) {
        $recipient = 'techie.girl@live.com';
      } else {
        $recipient = 'techiegirlsara@gmail.com';
      }
      return $recipient;
    } // end function wpcf7_dynamic_to_filter_example
    	add_filter('dynamic-to-from-values', 'my_dynamic_to'), 10, 2);
    
    ?>

    Here are my hidden fields:

    [hidden dynamic-mail-to-filter "wpcf7-dynamic-mail-to-example-filter"]
    [hidden dynamic-mail-to-fields "loan-amount,income,net-worth"]

    What am I doing wrong?

    Thread Starter techie.girl

    (@techiegirl-1)

    Sorry, there’s an error above. The value in my dynamic-mail-to-filter is dynamic-to-from-values, not wpcf7-dynamic-mail-to-example-filter as that’s the name of the filter itself. I copied it from the wrong place.

    Plugin Author John Huebner

    (@hube2)

    Do you have an ACF add on installed that adds hidden fields? You will need to use either my hidden field plugin https://wordpress.org/plugins/contact-form-7-simple-hidden-field/ or the dynamic text extension https://wordpress.org/plugins/contact-form-7-dynamic-select-extension/

    Thread Starter techie.girl

    (@techiegirl-1)

    We use Dynamic Text Extension. I know it works, I wrote a small jquery script to pull some info from an outside form and place it into hidden fields with a certain class and it works fine. All the data in the hidden fields come through. And with this, the two that I put in there have the right data in the db, the hook shows and the fields show as values in their respective fields.

    Plugin Author John Huebner

    (@hube2)

    I just noticed that you’re using my example file. By default this file is not actually included anywhere. Did you copy those functions to your functions.php file.

    The example file will get overwritten then next time I update the plugin.

    Thread Starter techie.girl

    (@techiegirl-1)

    That wasn’t in the instructions and the top of the examples file says ‘this file needs to be edited to work’ etc, so I assumed it was called from somewhere. But, I should have guessed that.

    However, when I put

    function my_dynamic_to($recipient, $args=array()) {
      if ((isset($args['income']) &&
           intval($args['income'] > 250000) ||
          (isset($args['net-worth']) &&
           intval($args['net-worth']) > 500000) ||
          (isset($args['loan-amount']) &&
           intval($args['loan-amount') > 1000000)) {
        $recipient = 'email1@email.com';
      } else {
        $recipient = 'email2@email.com';
      }
      return $recipient;
    } // end function wpcf7_dynamic_to_filter_example
    	add_filter('dynamic-to-from-values', 'my_dynamic_to'), 10, 2);

    Into the functions file the whole site goes white and I can’t get the source to pull up either. My guess is that there’s an extra ) or missing ‘ or so. I can’t see anything offhand, but I’ll keep tinkering. Any thoughts offhand?

    Plugin Author John Huebner

    (@hube2)

    I’ll make a not to make the example instructions more clear. I’ve also made a note to make the instructions here more clear as well.

    As far as the errors, turn on php error display on your site and that will probably tell you what’s wrong. It’s likely a syntax error, missing ; or something like that.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Help with arguments’ is closed to new replies.