Contact form 7 wordpress post 表单到不同域提供访问控制允许来源错误
Contact form 7 wordpress post form to different domain gives access control allow origin error
我正在尝试使用 Web to Lead html 代码将联系我们表单的详细信息发送到 Insightly CRM。我在 functions.php:
中使用以下代码更改了表单的操作 url
add_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url');
function wpcf7_custom_form_action_url($url) {
global $post;
$id_to_change = 1315;
if($post->ID === $id_to_change)
return 'https://xxxx.insight.ly/WebToLead/Create';
else
return $url;
}
检查器上一切正常,但我在提交时收到以下错误:
XMLHttpRequest cannot load https://xxxx.insight.ly/WebToLead/Create. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://xxxx.com' is therefore not allowed access.
我尝试将此添加到我的 functions.php:
add_action( 'init', 'allow_origin' );
function allow_origin() {
header("Access-Control-Allow-Origin: *");
}
我尝试在 theme.php 中添加这个:
header("Access-Control-Allow-Origin: *");
我尝试将此添加到联系表格 7 插件的 scripts.js:
$.ajax({
url: url,
++headers: { 'Access-Control-Allow-Origin': '*' },
++crossDomain: true,
我尝试将其添加到 .htaccess:
Header always set Access-Control-Allow-Origin "*"
没有任何效果:(
我的服务器有 Varnish 4 和 ConfigServer Security & Firewall,但我禁用了两者,但仍然出现相同的错误。
请帮助我:(
经过我的研究,我发现 javascript 是问题所在,我无法通过 Access-Control-Allow-Origin
以任何方式绕过它。
我在钩子 php 脚本中使用了 curl,因此它可以将详细信息发送到其他域。
所以我在我的 functions.php 中添加了一个钩子,我正在覆盖 wpcf7_mail_sent 函数:
add_filter('wpcf7_mail_sent', 'wpcf7_custom_mail_sent');
function wpcf7_custom_mail_sent($contact_form) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://xxxx.insight.ly/WebToLead/Create");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($_REQUEST));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
我正在尝试使用 Web to Lead html 代码将联系我们表单的详细信息发送到 Insightly CRM。我在 functions.php:
中使用以下代码更改了表单的操作 urladd_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url');
function wpcf7_custom_form_action_url($url) {
global $post;
$id_to_change = 1315;
if($post->ID === $id_to_change)
return 'https://xxxx.insight.ly/WebToLead/Create';
else
return $url;
}
检查器上一切正常,但我在提交时收到以下错误:
XMLHttpRequest cannot load https://xxxx.insight.ly/WebToLead/Create. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://xxxx.com' is therefore not allowed access.
我尝试将此添加到我的 functions.php:
add_action( 'init', 'allow_origin' );
function allow_origin() {
header("Access-Control-Allow-Origin: *");
}
我尝试在 theme.php 中添加这个:
header("Access-Control-Allow-Origin: *");
我尝试将此添加到联系表格 7 插件的 scripts.js:
$.ajax({
url: url,
++headers: { 'Access-Control-Allow-Origin': '*' },
++crossDomain: true,
我尝试将其添加到 .htaccess:
Header always set Access-Control-Allow-Origin "*"
没有任何效果:( 我的服务器有 Varnish 4 和 ConfigServer Security & Firewall,但我禁用了两者,但仍然出现相同的错误。 请帮助我:(
经过我的研究,我发现 javascript 是问题所在,我无法通过 Access-Control-Allow-Origin
以任何方式绕过它。
我在钩子 php 脚本中使用了 curl,因此它可以将详细信息发送到其他域。
所以我在我的 functions.php 中添加了一个钩子,我正在覆盖 wpcf7_mail_sent 函数:
add_filter('wpcf7_mail_sent', 'wpcf7_custom_mail_sent');
function wpcf7_custom_mail_sent($contact_form) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://xxxx.insight.ly/WebToLead/Create");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($_REQUEST));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}