【问题标题】:I have an AMP form but for some reason it has error while submitting我有一个 AMP 表单,但由于某种原因,它在提交时出错
【发布时间】:2020-05-16 09:50:02
【问题描述】:

我有一个带有 amp-form 组件的 AMP 网站,但由于某种原因无法提交表单。 控制台错误https://prnt.sc/shu7i0 和网络错误https://prnt.sc/shu85g。您也可以在这里查看直播网站https://frontlinewebtech.com/traderharian/。请帮忙

这是我的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>

这是我的 PHP

<?php
if(!empty($_POST)){
    $email = $_POST['email'];
    $formcontent=" From: $email";
    $recipient = "bishnu051@gmail.com";
    $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;
}
?>

【问题讨论】:

    标签: php amp-html amp-form


    【解决方案1】:

    我检查了你所有的附件,我发现这个错误是由于 406“不可接受”的原因。

    在此服务器上找不到所请求资源的适当表示。此错误是由 Mod_Security 生成的。

    复制下面的文本并将其粘贴到域根目录下的 .htaccess 文件中。

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

    或检查您的 apache mod_security 配置。

    useful link

    【讨论】:

    • 我关注了这个但是没有用,然后我联系了我的托管服务关于 mod_security 并且他们为我修复了它,谢谢你的洞察力,我真的很感激它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 2023-01-30
    • 2021-04-13
    • 2021-12-06
    相关资源
    最近更新 更多