如何解决联系表单中的错误AMP上提交?

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

我试图向从www.lightmorelight.com的形式,但我有在搜索控制台错误:响应必须包含AMP存取控制允许来源-Origin标。我无法弄清楚

这里是我的代码:

<?php 
if(isset($_POST['submit'])){

header("HTTP/2 200");
header("access-control-allow-headers: Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token");
header("access-control-allow-credentials: true");
header("access-control-allow-origin: https://lightmorelight.com");
header("amp-access-control-allow-source-origin: https://lightmorelight.com");
header("access-control-allow-methods: POST, GET, OPTIONS");
header("access-control-expose-headers: AMP-Access-Control-Allow-Source-Origin");
$name = $_POST['nume'];
$subject = $_POST['subiect'];
$message = $_POST['mesaj'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$from = "From:". $name ."<". $email .">";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers = "From: ".$name." <".$email.">\r\n";
$headers .= "Reply-To:".$name." <".$email.">\r\n";
$headers .= "Return-Path: lightmorelight.com<[email protected]>\r\n";
     $body = "$message\n\n
$name 
Tel: $tel
Email:$email_field";
mail('[email protected]','www.lightmorelight.com - '.$subject,$body,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
$string = "Thank you ".$name." for getting in touch! \\n\\nI appreciate you contacting me about ".$subject.". I will contact you shortly. \\n\\nHave a great day ahead!";
die("<script>alert(\"$string\");</script><script type=\"text/javascript\">window.location = \"https://www.lightmorelight.com/contact/\";</script>");
}
?>

<form action-xhr="#" method="POST" target="_top">
<input type="text" name="nume" placeholder="Nume" required><br/>
<input type="text" name="tel" placeholder="Tel" required><br/>
<input type="text" name="email" placeholder="Email" required><br/>
<input type="text" name="subiect" placeholder="Subiect" required><br/>
<textarea name="mesaj" placeholder="Mesaj..." rows="6" cols="30"></textarea><br/>
<input type="submit" name="submit" value="Trimite mesaj" class="button">
</form>

任何帮助,将不胜感激!

amp-html contact-form amp-form
1个回答
0
投票

如果您使用action-xhramp-form,响应从服务器返回的必须是JSON。

因为你的反应是HTML,你得到的错误从AMP运行时试图解析这个HTML作为JSON的到来。

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