验证码联系表格 7 "status: spam"在 Vue.js 应用程序



我构建了一个小型Vue.js应用程序,该应用程序在子域(与WordPress相同的主域(下运行,并使用axios包向联系人表单7rest API提交表单。不幸的是,我总是只收到"状态:垃圾邮件"作为回复。我已经为Vue.js应用程序设置了一个摘要,在主页上的WordPress摘要中,我还将新的子域列入了白名单。

如果我关掉Recaptcha,它会像预期的那样工作。

const formData = new FormData();
formData.append('customerName', this.formInput.customerName);
formData.append('customerEmail', this.formInput.customerEmail);
formData.append('customerPhonenumber', this.formInput.customerPhonenumber);
formData.append('date', this.formInput.date);
formData.append('privacy', this.formInput.privacy);
axios.post('https://MY_DOMAIN/wp-json/contact-form-7/v1/contact-forms/1347/feedback', formData)
.then((response) => {
console.log(response);
this.result.status = response.data.status;
this.result.message = response.data.message;
if (response.data.status === 'mail_sent') {
this.formInput.customerName = '';
this.formInput.customerEmail = '';
this.formInput.customerPhonenumber = '';
this.formInput.date = '';
this.formInput.privacy = 0;
}
});

对于那些正在寻找这个特定问题答案的人(我知道现在给出答案已经太晚了(。

正如OP所提到的,它被标记为垃圾邮件的原因是,

  1. 正如我在OP代码片段中看到的那样,我们不会将WP Nonce作为提交的一部分发送,也没有包含WP Nonce。如果您可以将WP Nonce作为提交给任何Wordpress-end(Rest-API等(的一部分,以避免任何问题,这是最佳实践。请参阅下面的代码,其中联系表格7也在检查WP Nonce
私有函数spam(({$spam=false;if($this->contact_form->is_true('subscribers_only'(&&current_user_can('wpcf7_submit',$this->contact_form->id((({return$spam;}$user_agent=(字符串($this->get_meta('user_agent'(;if(strlen($user_agent(verify_noce((({$spam=true;}if($this->is_blacklisted((({$spam=true;}return apply_filters('wpcf7_samp',$spam'(;}私有函数verify_noce(({if(!$this->contact_form->nonce_is_active((({返回true;}返回wpcf7_verify_nonce($_POST['_wpnonce'](;}
  1. 就像上一部分提到的OP一样,我怀疑OP目标的Contact Form字段中包含了Recaptcha字段,在这种情况下,我们必须在该特定表单中包含Recaptcha响应-因为Contact Form 7会检查是否有Recaptcha域和/或该字段不是空的。下面是检查Recaptcha的片段
add_filter('wpcf7_spam','wpcf7_recaptcha_check_with_google',9(函数wpcf7_recaptcha_check_with_google($spam({if($spam({return$spam;}$contact_form=wpcf7_get_current_contact_form((;if(!$contact_form({return$spam;}$tags=$contact_form->scan_form_tags(数组('type'=>'repatcha'((;if(空($tags(({return$spam;}$repatcha=WPCF7_CAPTCHA::get_instance((;if(!$repatcha->is_active((({return$spam;}$response_token=wpcf7_recaptcha_reresponse((;$spam=$重述->验证($response_token(;return$spam;}

为了解决这个问题,

  1. 对于WP Nonce,我们可以在发送提交时简单地包括它
  2. 对于Recaptcha,我们必须以某种方式生成Recaptcha结果,在我的情况下,幸运的是,我也有Recaptcha字段,所以我可以简单地获取该结果并在提交时传递它
  3. 为了将来参考,你可以检查这个答案——基本上和我之前提到的一样

祝未来遇到这个问题的人好运!:(

最新更新