在我们网站上的两个页面上,我基本上具有相同的PHP脚本。一种形式完美无瑕,另一种形式则引发以下错误: *响应必须包含AMP-Access-Control-Allow-Source-Origin标头 *表单提交失败:错误:响应必须包含AMP-Access-Control-Allow-Source-Origin标头
预订表格不起作用
<?php
if(isset($_POST['email'])) {
header("access-control-allow-credentials:true");
header("access-control-allow-headers:Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token");
header("access-control-allow-methods:POST, GET, OPTIONS");
header("access-control-allow-origin:".$_SERVER['HTTP_ORIGIN']);
header("access-control-expose-headers:AMP-Access-Control-Allow-Source-Origin");
header("amp-access-control-allow-source-origin:https://".$_SERVER['HTTP_HOST']);
header("Content-Type: application/json");
$email_to = "kevin@domain.com.tw;jypbobwr@mydomain.io";
$email_subject = "Booking Form";
$date = date('Y-m-d H:i:s');
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$event = $_POST['event'];
$time = $_POST['time'];
$guests = $_POST['guests'];
$highchair = $_POST['highchair'];
$ipaddress = $_SERVER['REMOTE_ADDR'];
$output = ['name' => $name];
$output = ['telephone' => $telephone];
$output = ['event' => $event];
$output = ['time' => $time];
$output = ['guests' => $guests];
$output = ['highchair' => $highchair];
$output = ['ipaddress' => $ipaddress];
echo json_encode($output);
}
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message = "Created: ".clean_string($date)."\n";
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Event: ".clean_string($event)."\n";
$email_message .= "Time: ".clean_string($time)."\n";
$email_message .= "Guests: ".clean_string($guests)."\n";
$email_message .= "Highchairs: ".clean_string($highchair)."\n";
$email_message .= "IP: ".clean_string($ipaddress)."\n";
$headers = 'From: '.$email_to."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
这种餐饮形式非常有用
<?php
if(isset($_POST['email'])) {
header("access-control-allow-credentials:true");
header("access-control-allow-headers:Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token");
header("access-control-allow-methods:POST, GET, OPTIONS");
header("access-control-allow-origin:".$_SERVER['HTTP_ORIGIN']);
header("access-control-expose-headers:AMP-Access-Control-Allow-Source-Origin");
header("amp-access-control-allow-source-origin:https://".$_SERVER['HTTP_HOST']);
header("Content-Type: application/json");
$email_to = "kevin@domain.com.tw;jypbobwr@mydomain.io";
$email_subject = "Catering Form";
$date = date('Y-m-d H:i:s');
$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$company = $_POST['company'];
$vat = $_POST['vat'];
$address = $_POST['address'];
$event = $_POST['event'];
$time = $_POST['time'];
$comments = $_POST['comments'];
$ipaddress = $_SERVER['REMOTE_ADDR'];
$output = ['name' => $name];
$output = ['email' => $email_from];
$output = ['telephone' => $telephone];
$output = ['company' => $company];
$output = ['vat' => $vat];
$output = ['address' => $address];
$output = ['event' => $event];
$output = ['time' => $time];
$output = ['comments' => $comments];
$output = ['ipaddress' => $ipaddress];
echo json_encode($output);
}
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message = "Created: ".clean_string($date)."\n";
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Company: ".clean_string($company)."\n";
$email_message .= "VAT: ".clean_string($vat)."\n";
$email_message .= "Address: ".clean_string($address)."\n";
$email_message .= "Event: ".clean_string($event)."\n";
$email_message .= "Time: ".clean_string($time)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$email_message .= "IP: ".clean_string($ipaddress)."\n";
$headers = 'From: '.$email_to."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
我正在拔头发。我可以看到没有理由不起作用。