如何从 Contact Form 7 中提交的数据中获取联系电子邮件?

How to get contact email from submitted data in Contact Form 7?

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

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

如何获取联系人的数据?

您想获取您的提交内容,然后使用您用于电子邮件的表单域来执行您想要的操作。

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