• Resolved synthview

    (@synthview)


    Hello John,
    I’m sorry bothering you mbut after some hours of testing I can’t figuring out how to make your plugin to work ??
    I’d like the user to select something from a select menu (such as I’m a private person, I’m professional, I’m a journalist, etc) to get the message to be dispatched to a specific email address.

    Could you please tell me if you see an issue in my code please?

    The fields I’ve set are:

    <label> Votre nom (required)
        [text* your-name] </label>
    
    <label> Objet de votre message
       [select* select-email  include_blank "Je suis un citoyen" "Je suis un media" "Je suis un investisseur" "Je souhaite rejoindre votre e?quipe " "je repre?sente une collectivite? locale"] </label>
    
    <label> Votre adresse email (required)
        [email* your-email] </label>
    
    <label> Votre message
        [textarea your-message] </label>
    
    [simplehidden dynamic-mail-to-filter "wpcf7-dynamic-mail-to-example-filter"]
    [simplehidden dynamic-mail-to-fields "select-email"]
    [submit "Send"]

    The echo from my form post is:

    Array
    (
        [_wpcf7] => 44
        [_wpcf7_version] => 4.9.2
        [_wpcf7_locale] => fr_FR
        [_wpcf7_unit_tag] => wpcf7-f44-o1
        [_wpcf7_container_post] => 0
        [your-name] => aasdf
        [select-email] => Je suis un investisseur
        [your-email] => [email protected]
        [your-message] => bgsdbsgdfgvwtdgvrtdf
        [dynamic-mail-to-filter] => wpcf7-dynamic-mail-to-example-filter
        [dynamic-mail-to-fields] => select-email
    )

    Is it correct?

    I’ve copied as-it-is your public function, into my functions.php and just updated the private $email_address_1 ='XXXXXX';

    (I had to comment new wpcf7_dynamic_mail_to_examples(); otherwise my WP crashed).

    I’ve of course installed both your plugins ??

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

    (@hube2)

    exactly what did you put into your functions.php file

    Thread Starter synthview

    (@synthview)

    this (emails addresses cloaked for this forum. By now I’m just testing for first 3 items of the select, not all)

    
    //not include css and js from ContactForm7
    add_filter( 'wpcf7_load_js', '__return_false' );
    add_filter( 'wpcf7_load_css', '__return_false' );
    
    //	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 = 'xxxxx.com';
    		private $email_address_2 = 'yyyyy.com';
    		private $email_address_3 = 'zzzzz.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()) {
    		
    			if (isset($args['select-email'])) {
    				if ($args['select-email'] == 'Je suis un citoyen') {
    					$recipient = $this->email_address_1;
    				} elseif ($args['select-email'] == 'Je suis un media') {
    					$recipient = $this->email_address_2;
    				} elseif ($args['select-email'] == 'Je suis un investisseur') {
    					$recipient = $this->email_address_3;
    				}
    			}
    			return $recipient;
    		} // end public function filter
    		
    	} // end class wpcf7_dynamic_mail_to_examples
    	
    • This reply was modified 6 years, 10 months ago by synthview.
    Thread Starter synthview

    (@synthview)

    in fact I have the feeling the hook doesn’t fire.If I set a print_r and a die inside, nothing outputs.

    Plugin Author John Huebner

    (@hube2)

    you have this line commented so the object is never instantiated

    
    //	new wpcf7_dynamic_mail_to_examples();
    

    or you can try the non OOP example that’s included (and commented out) in the same file.

    Thread Starter synthview

    (@synthview)

    if I uncomment I see this

    Fatal error: Class 'wpcf7_dynamic_mail_to_examples' not found in /xx/yy/zz/themes/velocita/functions.php on line 163

    (163 is the line of new wpcf7_etcetc)
    the other example didn’t work neither ??

    • This reply was modified 6 years, 10 months ago by synthview.
    Thread Starter synthview

    (@synthview)

    my local server (Mamp) has php 5.5.3, does it matter?

    Thread Starter synthview

    (@synthview)

    Well, with the classic hook it works now…
    I think I didn’t get the good naming of the hook into here

    
    [simplehidden dynamic-mail-to-filter "wpcf7-dynamic-recipient-example-filter"]

    Thanks for your help!! It was very useful to check again things ??

    Plugin Author John Huebner

    (@hube2)

    it shouldn’t matter, try moving the new ... line to after the class code.

    Unless you have something else going on. However, it should not matter if you instantiate the object before or after the class is include unless your functions.php file is loaded in a way I’m not familiar with.

    With the fields you’ve created the non-oop code should also be working. If you use this code, is the filter running? If you put a print_r… die statement in it do you get the output?

    Thread Starter synthview

    (@synthview)

    I’ve tried putting the new after or before the class and it crashes.
    It worked once (my previous post) but now it works no more ??

    Thread Starter synthview

    (@synthview)

    now print_r($args); echo $recipient; die; works!

    I see it bugs on when I have accented letters in my select options.
    I’ve tried to mark them as &eacute;

    Array ( [select-email] => Je souhaite rejoindre votre ??quipe )
    it should be équipe
    In CF7 configurator I’ve set
    Je souhaite rejoindre votre &eacute;quipe

    • This reply was modified 6 years, 10 months ago by synthview.
    Thread Starter synthview

    (@synthview)

    I’ve found there is a native way for CF7 to get the wanted result.
    Thanks anyway ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘mail sent to default WP user’ is closed to new replies.