0

我尝试从 www.lightmorelight.com 提交表单,但在搜索控制台中出现错误:响应必须包含 AMP-Access-Control-Allow-Source-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<iustinbeceneaga86@gmail.com>\r\n";
     $body = "$message\n\n
$name 
Tel: $tel
Email:$email_field";
mail('iustinbeceneaga86@gmail.com','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>

任何帮助,将不胜感激!

4

1 回答 1

0

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

因为您的响应是 HTML,所以您收到的错误来自 AMP 运行时试图将此 HTML 解析为 JSON。

于 2019-02-05T00:07:12.110 回答