【问题标题】:How to get contact email from submitted data in Contact Form 7?如何从联系表 7 中提交的数据中获取联系电子邮件?
【发布时间】:2020-05-15 11:31:44
【问题描述】:

我想使用联系表 7 为用户订阅我的其他时事通讯系统。我尝试使用以下代码从提交的表单中获取收件人电子邮件,但它返回发件人(管理员)电子邮件。

add_action('wpcf7_before_send_mail', function ($contact_form) {
    $mailProp = $contact_form->get_properties('mail');
    subscribe_to_another_newsletter($mailProp['mail']['recipient']);
});

如何获取联系人的数据?

【问题讨论】:

    标签: wordpress contact-form-7 newsletter


    【解决方案1】:

    您想获取您提交的内容,然后使用您用于电子邮件的表单字段来做您想做的事情。

    add_action( 'wpcf7_before_send_mail', array($this, 'cf7_process_form'));
    function my_cf7_process_form(){
        // This calls the static get the cf7 form data
        $submission = WPCF7_Submission::get_instance();
           if ( $submission ) {
            // $posted_data = array with all form fields
            $posted_data = $submission->get_posted_data();    
        }
        // if [your-email] is the form tag
        $email = $posted_data['your-email'];
        subscribe_to_another_newsletter($email);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-11
      • 2016-08-12
      • 2021-09-24
      • 2019-11-22
      • 1970-01-01
      相关资源
      最近更新 更多