1

I have two versions of an auto responder that I would like to send out based on what the user selected from a dropdown field. So if the user selected California from the dropdown they would get autoresponder 1 and if the user selected Texas they would get auto responder 2. Is there a way to do this?

cloudnine
  • 11
  • 1
  • 3

2 Answers2

1

Where exactly should be this code added?

hook in to wpcf7_mail_sent - this will happen after form is submitted

add_action( 'wpcf7_mail_sent', 'contact_form_autoresponders' );

our autoresponders function

function contact_form_autoresponders( $contact_form ) {

    if( $contact_form->id==1234 ){ #your contact form ID - you can find this in contact form 7 settings

        #retrieve the details of the form/post
        $submission = WPCF7_Submission::get_instance();
        $posted_data = $submission->get_posted_data();                          

        #set autoresponders based on dropdown choice            
        switch( $posted_data['location'] ){ #your dropdown menu field name
            case 'California':
            $msg="California email body goes here";
            break;

            case 'Texas':
            $msg="Texas email body goes here";
            break;

        }

        #mail it to them
        mail( $posted_data['your-email'], 'Thanks for your enquiry', $msg );
    }

}

Community
  • 1
  • 1
ex501
  • 53
  • 7
  • This worked for me but I was tripped up because my checkbox input was returning an array. I got around that issue like this: $posted_data['my-checkbox-field'][0] – DeFeNdog Jan 26 '18 at 22:15
0

Add in functions.php -

#hook in to wpcf7_mail_sent - this will happen after form is submitted
add_action( 'wpcf7_mail_sent', 'contact_form_autoresponders' ); 

#our autoresponders function
function contact_form_autoresponders( $contact_form ) {

        if( $contact_form->id==1234 ){ #your contact form ID - you can find this in contact form 7 settings

            #retrieve the details of the form/post
            $submission = WPCF7_Submission::get_instance();
            $posted_data = $submission->get_posted_data();                          

            #set autoresponders based on dropdown choice            
            switch( $posted_data['location'] ){ #your dropdown menu field name
                case 'California':
                $msg="California email body goes here";
                break;

                case 'Texas':
                $msg="Texas email body goes here";
                break;

            }

            #mail it to them
            mail( $posted_data['your-email'], 'Thanks for your enquiry', $msg );
        }

}
lumonald
  • 344
  • 4
  • 11