基于联系表 7 字段的条件自动回复

问题描述 投票:0回答:1

我想根据 Contact Form 7 表单中选择的字段设置自动回复器。例如,我将根据“职位名称”字段更改表单的字段。该字段将包含“职务 1”“职务 2”。发送自动回复时,它只会包含一条基于选择两个职位之一的消息。

任何帮助将不胜感激!

更新:

所以我尝试了这里的建议条件自动回复器是联系表格7

这是他们建议的代码:

#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==1 ){ #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['position'] ){ #your dropdown menu field name
            case 'Media Buyer':
            $msg="This is an auto response for Media Buyer";
            break;

            case 'Agency':
            $msg="This is an auto response for Agency";
            break;

            case 'Business Owner':
            $msg="This is an auto response for Business Owner";
            break;

        }

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

}

尝试此操作后,我没有看到基于选择三个位置之一的响应,也没有看到任何自动响应。我猜这会覆盖 CF7 控制面板上的 Mail 2 功能?我已经尝试过检查过和不检查过。

php wordpress forms contact-form-7
1个回答
0
投票

我遇到了同样的问题,但通过将 switch 结构更改为 if 来解决它,如下所示:

#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            
        if ($posted_data['location']=='California'){
            $msg="California email body goes here";
        } else 
        {$msg="Texas email body goes here`enter code here";}

        #mail it to them
        mail( $posted_data['your-email'], 'Thanks for your enquiry', $msg, );
    }
© www.soinside.com 2019 - 2024. All rights reserved.