报告表未提交(php,html)



我正在创建一个小网站,我有一个问题报告表。问题是电子邮件没有发送。我不确定我做错了什么。 我认为 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.".nn";

mail($mailTo, $txt, $headers);
header("Location: /index.html?reportsent");
}
?>

JavaScript

function 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;
}

谢谢!

通过检查邮件函数的参数...

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' . "rn" .
'Reply-To: noreply@rileysunblockedgames.com' . "rn" .
'X-Mailer: PHP/' . phpversion();
$txt = "You have received a report form message: ".$name.".nn";
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">

最新更新