表单输出空响应,并且不发送任何内容

非常有必要使此表单从网站发送姓名和电话号码。当我尝试发送数据时 - 单击发送按钮后 - 我看到一个空的模式窗口而不是响应 - 发送或未发送。文件内容发送.php


<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    if (isset($_POST['name'])) {$name = $_POST['name'];}

    if (isset($_POST['phone'])) {$phone = $_POST['phone'];}


    $to = "recipient@gmail.com";

    $sendfrom   = "sender@mail.ru";

    $headers  = "From: " . strip_tags($sendfrom) . "\r\n";

    $headers .= "Reply-To: ". strip_tags($sendfrom) . "\r\n";

    $headers .= "MIME-Version: 1.0\r\n";

    $headers .= "Content-Type: text/html;charset=utf-8 \r\n";

    //$subject = "$formData";

    $message = "<br><b>Имя пославшего:</b>". $name ."<br><b>Телефон:</b>". $phone;

    $send = mail ($to, $headers, $message);

    if ($send == 'true')

    {

        echo '<p class="success">Спасибо за отправку вашего сообщения!</p>';

    } else {

        echo '<p class="fail"><b>Ошибка. Сообщение не отправлено!</b></p>';

    }

} else {

    http_response_code(403);

    echo "Попробуйте еще раз";

}

?>



尚方宝剑之说
浏览 62回答 2
2回答

慕后森

您在HTML中有两个嵌套表单,嵌套的HTML表单是不允许的,正如@Abdulla Nilam和HTML5的工作草案所提到的:来自 html5 工作草案:4.10.3 表单元素内容模型:流内容,但没有表单元素后代。要使其工作,您应该删除第一个表单,因为它没有操作或方法:<link rel="stylesheet" href="../css/feedback/remodal.css"><link rel="stylesheet" href="../css/feedback/remodal-default-theme.css"><a class="mainButton" href="#modal">Callback</a><div class="remodal" data-remodal-id="modal" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">&nbsp;<div class="remodalBorder">&nbsp; <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>&nbsp; &nbsp; &nbsp; &nbsp; <form id="form" action="../php/feedback/send.php" method="POST">&nbsp; &nbsp; &nbsp; &nbsp; <p><span class="formlable" style="text-transform: uppercase;">You name</span><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="text" class="putName" name="name"&nbsp; cols="67%" placeholder="Required field" required>&nbsp; &nbsp; &nbsp; &nbsp; <p><span class="formlable" style="text-transform: uppercase;">Phone number</span><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input name="phone" type="tel" class="putPhone" placeholder="Required field" required>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="submit" name="submit" class="btn" value="Order a call">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="hidden" name="formData" value="Application from the site">&nbsp; &nbsp; &nbsp; &nbsp; <br><br>By clicking on the "Order a call" button, you give <a class="mainArticlesTextAgree"&nbsp; href="../agreement.html">consent to the processing of</a> your personal data.&nbsp;&nbsp;</div></div><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><script src="../js/feedback/remodal.min.js"></script><script src="../js/feedback/script.js"></script>&nbsp;

慕田峪4524236

试试这个HTML表单<a class="mainButton" href="#modal">Callback</a><div class="remodal" data-remodal-id="modal" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">&nbsp; <div class="remodalBorder">&nbsp; &nbsp; <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>&nbsp; &nbsp; <form id="form" action="../php/feedback/send.php" method="POST">&nbsp; &nbsp; &nbsp; <p><span class="formlable" style="text-transform: uppercase;">You name</span><br>&nbsp; &nbsp; &nbsp; &nbsp; <input type="text" class="putName" name="name"&nbsp; cols="67%" placeholder="Required field" required>&nbsp; &nbsp; &nbsp; </p>&nbsp; &nbsp; &nbsp; <p><span class="formlable" style="text-transform: uppercase;">Phone number</span><br>&nbsp; &nbsp; &nbsp; &nbsp; <input name="phone" type="tel" class="putPhone" placeholder="Required field" required>&nbsp; &nbsp; &nbsp; &nbsp; <input type="submit" name="submit" class="btn" value="Order a call">&nbsp; &nbsp; &nbsp; &nbsp; <input type="hidden" name="formData" value="Application from the site">&nbsp; &nbsp; &nbsp; </p>&nbsp; &nbsp; &nbsp; <br><br>&nbsp; &nbsp; &nbsp; By clicking on the "Order a call" button, you give <a class="mainArticlesTextAgree"&nbsp; href="../agreement.html">consent to the processing of</a> your personal data.&nbsp; &nbsp; </form>&nbsp; </div></div>
打开App,查看更多内容
随时随地看视频慕课网APP