我最近也用php创建了一个联系表单,但每次点击提交时,我只会得到一个未定义的错误,没有别的。任何人都可以了解我错过的内容吗?
HTML
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="contactengine.php">
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="Name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="Email" class="form-control" required="required">
</div>
<div class="form-group">
<label>Phone *</label>
<input type="number" name="Phone" class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="Message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
PHP
<?php
if (isset($_POST["submit"])){
$EmailFrom = "$Email";
$EmailTo = "ben.afunsho@gmail.com";
$Subject = "New Message from Your Message";
$Name = trim(stripslashes($_POST['Name']));
$Phone = trim(stripslashes($_POST['Phone']));
$Email = trim(stripslashes($_POST['Email']));
$Subject = trim(stripslashes($_POST['Subject']));
$Message = trim(stripslashes($_POST['Message']));
// validation
$validationOK = true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "You have received a new email from";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= "$Subject: ";
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message; $Body .= "\n";
// send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}else {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
}
?>
我只在html上得到一个未定义的错误
答案 0 :(得分:0)
您的帖子中存在一些区分大小写问题,我对其进行了更正,并在相应的位置进行了评论。 检查
<?php
if (isset($_POST["submit"]))
{ $EmailFrom = "$Email";
$EmailTo = "ben.afunsho@gmail.com";
$Subject = "New Message from Your Message";
$Name = trim(stripslashes($_POST['Name']));
$Phone = trim(stripslashes($_POST['Phone']));
$Email = trim(stripslashes($_POST['Email']));
$Subject = trim(stripslashes($_POST['subject'])); //s should be small
$Message = trim(stripslashes($_POST['message'])); // m should be small
// validation
$validationOK = true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit;
}
// prepare email body text
$Body = "You have received a new email from";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $Subject; // copy paste is very bad
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page i
if ($success) { print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; }
else { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; }}?>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="contactengine.php">
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="Name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="Email" class="form-control" required="required">
</div>
<div class="form-group">
<label>Phone *</label>
<input type="number" name="Phone" class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="Message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary btn-lg" value="Submit" />
</div>
</div>
</form>