0

单击发送时,表单最多需要 30 秒才能发送。

表格正在工作,它最终会发送。

如果我检查页面并查看网络以尝试查看发生了什么,它会按预期立即发送。正常查看页面时确实很慢。

我不知道是什么原因造成的?还有其他人有类似的问题吗?

我已联系我的托管公司以确认问题是我的问题,而不是服务器问题。

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 = "hello@example.co.uk";
    $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");
        }     
}
?>
4

0 回答 0