У меня в основном один и тот же 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 = "[email protected];[email protected]";
$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 = "[email protected];[email protected]";
$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);
?>
Я вытаскиваю свои волосы. Для этого нет причин не работать, что я вижу.
Задача ещё не решена.
Других решений пока нет …