联系表 7 的条件自动回复

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

尝试根据输入字段中的内容实现联系表单 7 的有条件自动回复。该线程(Conditional auto responder is Contact Form 7)提出了一个解决方案,但通过“snippets”插件实现代码似乎不起作用 - 没有发送邮件响应。

如果可能,请告知如何使用 cf7 实现以下代码。谢谢,

#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 );
    }
}
php wordpress contact-form-7
2个回答
1
投票

下拉列表中存储的数据默认是一个数组。既然如此,你们已经很接近了。但是,您还应该使用

wp_mail
而不是
mail

add_action( 'wpcf7_mail_sent', 'contact_form_autoresponders' );

function contact_form_autoresponders( $contact_form ) {
    // The contact form ID.
    if ( 1234 === $contact_form->id ) {
        $submission  = WPCF7_Submission::get_instance();
        $posted_data = $submission->get_posted_data();
        // Dropdowns are stored as arrays.
        if ( isset( $posted_data['location'] ) ) {
            switch ( $posted_data['location'][0] ) {
                case 'California':
                    $msg = 'California email body goes here';
                    break;
                case 'Texas':
                    $msg = 'Texas email body goes here';
                    break;
                default:
                    $msg = 'Unfortunately, that location is not available';
            }
            // mail it to them using wp_mail.
            wp_mail( $posted_data['my-email'], 'Thanks for your enquiry', $msg );
        }
    }
}

0
投票

这个话题对我来说很有趣。我已经在 Wordpress 上构建了一个登陆页面,其中包含使用联系表单 7 制作的联系表单。我目前正在尝试发送不同的自动回复电子邮件,具体取决于用户在复选框字段上选择的选项。

这个想法是用户选择书籍的“数字版”或“印刷版”。然后他们将收到一封印刷版的确认电子邮件或一封包含数字版书籍链接的电子邮件。

你的功能能用吗?如果是,我应该使用联系表格 7 将其上传到我的网站上的哪里?

谢谢你!

© www.soinside.com 2019 - 2024. All rights reserved.