为了账号安全,请及时绑定邮箱和手机立即绑定

报告表格未提交(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 = "contact@email.com";    $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 = "contact@rileysunblockedgames.com";

    $subject = "Report Form Message";

    $headers = 'From: noreply@rileysunblockedgames.com' . "\r\n" .

    'Reply-To: noreply@rileysunblockedgames.com' . "\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 关注
  • 140 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信