I have an AMP form but for some reason it has error while submitting

239 Views Asked by At

I have am AMP site with amp-form component and for some reason just cant get the form to submit. The error on console https://prnt.sc/shu7i0 and network error https://prnt.sc/shu85g. You can also take a look at the live site here https://frontlinewebtech.com/traderharian/ . Please help

Here is my html

<form class="subscribe-form flex flex-middle" method="POST" action-xhr="/mail.php" target="_top">
    <div class="form-control">
        <input type="email" required name="email" placeholder="Alamat email">
    </div>
    <button class="btn-subscribe" type="submit">Daftar</button>
</form>

Here is my PHP

<?php
if(!empty($_POST)){
    $email = $_POST['email'];
    $formcontent=" From: $email";
    $recipient = "[email protected]";
    $subject = "email from website";
    $mailheader = "From: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

    $domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
    header("Content-type: application/json");
    header("Access-Control-Allow-Credentials: true");
    header("Access-Control-Allow-Origin: ". str_replace('.', '-','https://frontlinewebtech.com/'));
    header("AMP-Access-Control-Allow-Source-Origin: " . $domain_url);
    header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
    header("AMP-Redirect-To: https://example.com/index.html");
    header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
    echo json_encode(array('name' => $name));
    exit;
}
?>
1

There are 1 best solutions below

1
On BEST ANSWER

I checked your all attachements and I found that this error is due to 406 "Not Acceptable" reason.

An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.

Copy below text and paste it in the .htaccess file at the root of your domain.

<IfModule mod_security.c> SecFilterEngine Off SecFilterScanPOST Off </IfModule>

or check your apache mod_security configurations.

useful link