0

我敢肯定我只是错过了一些非常简单的东西,因为我已经从编码中筋疲力尽了。有人可以找出问题所在吗?提交表单时,会通过电子邮件发送信息,但电子邮件中不包含任何变量(如名字、姓氏等)。

我得到的是:

发件人:
电话: -- 回电:
最佳通话时间:
留言:

如果您能找到问题所在 - 我将非常感激。

这是 HTML 表单:

<form action="mail.php" method="POST" id="main_form" onSubmit="this.reset();">
<p>First Name</p> <input type="text" name="firstname" size="93" style="width:475px; float:left;"><br />
<p>Last Name</p> <input type="text" name="lastname" size="93" style="width:475px; float:left;"><br />
<p>Email</p> <input type="text" name="email" size="93" style="width:475px; float:left;"><br />
<p>Confirm E-mail</p> <input type="text" name="confirmemail" size="93" style="width:475px; float:left;"><br />
<p>Contact Number<br />
<input type = "text" id = "Ph1" name="Ph1" size =" 3" maxlength = "3" onkeyup = "validate(this,2)">-
<input type = "text" id = "Ph2" name="Ph2" size =" 3" maxlength = "3" onkeyup = "validate(this,3)">-
<input type = "text" id = "Ph3" name="Ph3" size =" 4" maxlength = "4" onkeyup = "validate(this,3)">
</p>
<script type = "text/javascript">
function validate(which,next) {
var val = which.value;
val = val.replace(/[^0-9]/g,"");  // strip non-digits
which.value = val;
next = "Ph" + next;
if (val.length == 3) {  // field completed
document.getElementById(next).focus()
}
}
</script>

<p>Request Phone Call:<br />
<span style="font-family:'Open Sans', serif; font-size:14px;">Yes:</span><input type="radio" value="Yes" name="call">
<span style="font-family:'Open Sans', serif; font-size:14px;">No:</span><input type="radio" value="No" name="call"><br />
</p>
<p>Best time to contact:<br />
<span style="font-family:'Open Sans', serif; font-size:14px;">Morning:<input type="radio" value="Morning" name="calltime">
<span style="font-family:'Open Sans', serif; font-size:14px;">Afternoon:<input type="radio" value="Afternoon" name="calltime">
<span style="font-family:'Open Sans', serif; font-size:14px;">Evening:<input type="radio" value="Evening" name="calltime"><br />
</p>
<p>Message</p><textarea name="message" rows="6" cols="67"></textarea><br />
<input class = "_submit"type="submit" value="SUBMIT" style="width: 128px;
height: 36px;
font-family: 'Pathway Gothic One', serif;
font-size: 28px;
border-radius: 0px;
border-width: 0px;
color: #FFF;
background-color: #FFCA04; float:left; margin-top: 10px;">
</form>

这是mail.php

<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$confirmemail = $_POST['confirmemail'];
$phone1 = $_POST['Ph1'];
$phone2 = $_POST['Ph2'];
$phone3 = $_POST['Ph3'];
$call = $_POST['call'];
$calltime = $_POST['calltime'];
$message = $_POST['message'];
$formcontent=" From: $firstname $lastname \n Phone: $phone1-$phone2-$phone3 \n Call Back: $call \n Best time to call: $calltime \n Message: $message";
$recipient = "MyEmail@domain.com";
$subject = "YOU HAVE A MESSAGE FROM WEBSITE CONTACT PAGE";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
4

2 回答 2

1
onSubmit="this.reset();"

您在提交开始时擦除所有数据。

(事件处理程序在事件的正常行为解决之前触发,以便可以取消行为)。

于 2013-09-12T21:38:05.773 回答
0

尝试从表单的 onSubmit 属性中删除“this.reset()”:

<form action="mail.php" method="POST" id="main_form" onSubmit="this.reset();">

事件处理程序在采取实际提交操作之前触发。如果你想在提交表单后在 JS 中做点什么,看看 这个 stackoverlow 帖子。它解释了如何提交表单并在提交后执行操作。

于 2013-09-12T21:39:29.947 回答