亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

報告表格未提交(php、html)

報告表格未提交(php、html)

PHP
心有法竹 2023-07-08 22:08:03
我正在創建一個小型網站,并且有一個問題報告表。問題是電子郵件未發送。我不確定我做錯了什么。我認為 php 或 html 可能有問題,我不是最擅長表單的。謝謝您的幫助!這是我的代碼:html <h2 style="font-size:30px;"><i class="fa fa-exclamation-circle"></i> Report</h2>    </div>    <hr class="descriptionline3">    <div class="modal-body3">        <form action="report.php" id="errorform" onsubmit = "return validate();">      <p style="color:#363636;text-align:left;padding-left:10px;">What seems to be the problem?</p>      <input type="text" class="forminputproblem" id="name" placeholder="Write the problem here..." style="height:20px;font-size:14px;border-radius:6px;display:inline-block;border:1px solid #ccc;padding: 12px 20px;">        <div style="height:10px;"></div>           <div style="color:red;" id="error_message"></div>        <div style="color:green;" id="success_message"></div>        <div style="height:10px;"></div>       <input name="sumbit" type="submit" value="SEND REPORT"></form>php<?php    if (isset($_POST['submit'])) {        $name = $_POST['name'];    $mailTo = "[email protected]";    $headers = "Report Form Message";    $txt = "You have received a report form message: ".$name.".\n\n";mail($mailTo, $txt, $headers);header("Location: /index.html?reportsent");    }?>javascriptfunction validate(){  var name = document.getElementById("name").value;  var error_message = document.getElementById("error_message");    error_message.style.padding = "10px";    var text;  if(name.length < 10){    text = "&#10006; Report message has to be at least 10 characters!";    error_message.innerHTML = text;    text = "";    success_message.innerHTML = text;    return false;  }  text = "";    error_message.innerHTML = text;text = "&#10004; Report has been submitted! We will get back to you as soon as possible.";    success_message.innerHTML = text;    return true;}謝謝!
查看完整描述

1 回答

?
瀟湘沐

TA貢獻1816條經驗 獲得超6個贊

通過檢查郵件功能的參數...

mail($to,?$subject,?$message,?$headers);

看來問題是你的變量有點混亂。此外,“標頭”并不指主題:電子郵件標頭包含信息并具有自己的語法。試試這個代碼:

<?php


? ? if (isset($_POST['submit'])) {

? ? ? ? $name = $_POST['name'];


? ? $mailTo = "[email protected]";

? ? $subject = "Report Form Message";

? ? $headers = 'From: [email protected]' . "\r\n" .

? ? 'Reply-To: [email protected]' . "\r\n" .

? ? 'X-Mailer: PHP/' . phpversion();

? ? $txt = "You have received a report form message: ".$name.".\n\n";


? ? mail($mailTo, $subject, $txt, $headers);

? ? header("Location: /games.html?reportsent");


? ? }


?>

此外,在您的輸入中,您必須定義“name”屬性才能正常工作:


<input type="text" class="forminputproblem" name="name" id="name" placeholder="Write the problem here..." style="height:20px;font-size:14px;border-radius:6px;display:inline-block;border:1px solid #ccc;padding: 12px 20px;">

另外(有趣的是,這是你現在遇到的最大障礙),你的提交按鈕的名稱中有一個拼寫錯誤,所以你的 PHP 代碼永遠不會運行:


<input name="submit" type="submit" value="SEND REPORT">


查看完整回答
反對 回復 2023-07-08
  • 1 回答
  • 0 關注
  • 167 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號