AMP form problems (very slow)

99 Views Asked by At

When clicking send the form is taking upto 30 seconds to send.

The form is working, it does send eventually.

If I inspect the page and view network to try and see what is going on it sends instantly as expected. When viewing the page normally it is really slow.

I have no idea what would be causing this? Does anyone else have a similar issue?

I have contacted my hosting company to confirm the issue is my end rather than a server issue.

HTML

<form method="post" action-xhr="send-form.php">
Your name:<br>
           <input type="text" name="namee" required  />
           Your telephone number:<br>
            <input type="text" name="phone" required />
            Your email address:<br>
           <input type="text" name="email" required />
           Your message:<br>
           <textarea name="message"></textarea>

            <input type="submit" class="imgcenter" value="" background-image: url(https://www.example.co.uk/img/send.png);"/>
</form>

PHP

<?php
if( !empty($_POST) ){

    $email = $_POST['email'];
    $namee = $_POST['namee'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];

    $formcontent=" From: $email" . "$namee" . "$phone" . "$message";
    $recipient = "[email protected]";
    $subject = "Enquiry";
    $mailheader = "From: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

    $domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
    $redirect_url = 'https://www.example.co.uk/thanks.html'; //-->MUST BE 'https://';

    header("Content-type: application/json");
    header("Access-Control-Allow-Credentials: true");
    header("Access-Control-Allow-Origin: *.ampproject.org");
    header("AMP-Access-Control-Allow-Source-Origin: ".$domain_url);


        if( empty($redirect_url) ){
            header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
        }else{
            header("AMP-Redirect-To: ".$redirect_url);
            header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin");
        }     
}
?>
0

There are 0 best solutions below