• Resolved danielshafer

    (@danielshafer)


    I can’t get the plugin to work for some reason. Running the current versions of WordPress and CF7. Thoughts?

    I’ve followed the instructions as closely as possible:
    1) adding the select with “[select select-email “send to email 1” “send to email 2” “send to email 3″]”

    2) adding to the form “<p class=”hidden-fields”>[simplehidden dynamic-mail-to-filter “select-email”]</p>”

    3) updating the emails in the cf7-dynamic-mail-to-examples.php file to be the real addresses.

    And of course, both plugins are activated and CF7 is working properly on it’s own. Thanks so much!

    https://www.ads-software.com/plugins/contact-form-7-dynamic-mail-to/

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

    (@hube2)

    The file cf7-dynamic-mail-to-examples.php in not included automatically by the plugin. The file is meant as an example of code you should put into your functions.php file.

    Thread Starter danielshafer

    (@danielshafer)

    I’ve added the following (but with real email addresses) to the functions.php but still no luck. Hopefully it’s something simple that I’m missing. Thanks!

    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 = '[email protected]';
    	private $email_address_2 = '[email protected]';
    	private $email_address_3 = '[email protected]';
    
    	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
    
    new wpcf7_dynamic_mail_to_examples();
    
    function wpcf7_dynamic_to_filter_example() {
    	if (isset($args['select-email'])) {
    		if ($args['select-email'] == 'send to email 1') {
    			$recipient = '[email protected]';
    		} elseif ($args['select-email'] == 'send to email 2') {
    			$recipient = '[email protected]';
    		} elseif ($args['select-email'] == 'send to email 3') {
    			$recipient = '[email protected]';
    		}
    	}
    	return $recipient;
    } // end function wpcf7_dynamic_to_filter_example
    add_filter('wpcf7-dynamic-recipient-example-filter', 'wpcf7_dynamic_to_filter_example', 10, 2);
    Plugin Author John Huebner

    (@hube2)

    Reading over your OP, I did see a problem with your setup, I’ll get tot that in a minute.

    You don’t need to copy both the class and the function from the examples file. The examples show the same thing done in two different ways for those that would rather work in a specific way. For example, I build with PHP classes an almost never use simple functions.

    The problem with your setup is that you want to base the email recipient on another field but you are not passing that field to the filter. this is referenced in this part of the instructions:

    If you would like the values of other fields sent to your filter as arguments, add a field with the name of “dynamic-mail-to-fields.” Set the value of this field to a comma separated list of the fields values you want sent to your filter. Again, see the example filter supplied with this plugin.

    Here is an example form using CF7 with the needed setup:

    <p>Your Name (required)<br />
        [text* your-name] </p>
    
    <p>Your Email (required)<br />
        [email* your-email] </p>
    
    <p>Subject<br />
        [text your-subject] </p>
    
    <p>Your Message<br />
        [textarea your-message] </p>
    
    <p>Select Email<br />
        [select select-email "send to email 1" "send to email 2" "sent to email 3"] </p>
    
    <!-- the name of the filter to use -->
    [simplehidden dynamic-mail-to-filter "wpcf7-dynamic-mail-to-example-filter"]
    <!-- the name of the select field to pass to the filter -->
    [simplehidden dynamic-mail-to-fields "select-email"]
    
    <p>[submit "Send"]</p>

    Thread Starter danielshafer

    (@danielshafer)

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Configuration problem’ is closed to new replies.