Conditional auto responder is Contact Form 7

自闭症网瘾萝莉.ら 提交于 2019-12-01 09:42:35

问题


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?


回答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 );
    }

}




回答2:


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 );
        }

}


来源:https://stackoverflow.com/questions/35782282/conditional-auto-responder-is-contact-form-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!