我已经用PHP验证做了一个简单的表格但实际上,我遇到了一个问题,因为我不是一个没有被整理出来的专业人士,详情如下:
表单HTML:
<div class="formbx">
<h2 class="git text-center" style="margin-top: 5px;">GET IN <span style="color: #ff3600;">TOUCH</span></h2>
<div class="frmer ">
<form action="contacts.php" method="POST" name="contactform">
<input id="txtexpName" style="border: none; margin-bottom: 15px; height: 30px; width: 100%; padding-left: 55px;" name="name" type="text" placeholder="Your Name" />
<div class="txtexpPhoneCntr">
<input id="txtexpPhone" style="border: none; margin-bottom: 15px; height: 30px; width: 100%; padding-left: 85px;" maxlength="10" name="phone" type="text" placeholder="Mobile Number" />
</div>
<input id="txtexpEmail" style="border: none; margin-bottom: 15px; height: 30px; width: 100%; padding-left: 55px;" name="email" type="text" placeholder="Email Address" />
<input id="txtexpCity" style="border: none; margin-bottom: 15px; height: 30px; width: 100%; padding-left: 55px;" name="name" type="text" placeholder="Your City" />
<textarea id="txtexpQuery" name="message" placeholder="Message"></textarea>
<div class="clearfix"> </div>
<button id="send" name="send" type="submit">Submit</button>
<div class="loading"> </div>
<div class="clearfix"> </div>
<label id="ErrorMsgExp" class="alert alert-danger" style="display: none; padding: 4px;"></label>
<label id="SuccessMsgExp" class="alert alert-success" style="display: none; padding: 4px;">Thank you for your interest.</label>
</form>
</div>
</div>
PHP代码:
<?php
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$city = $_POST['city'];
$message = $_POST['message'];
$formcontent=" Someone Contacted. Here are the details: \n Name: $name \n Mobile Number: $phone \n Email: $email \n City: $city \n Message: $message";
$recipient = "webdesigndevil0@gmail.com";
$subject = "Someone Contacted From Your Website";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact' style='text-decoration:none;color:#ff3600;'> Return Home</a>";
?>
在提交显示&#34;错误&#34;的表单后,我没有在导致错误的地方找到它,是否有语法错误?
答案 0 :(得分:0)
您使用此名称属性两次:name="name"
(第二次在“txtexpCity”输入标记中)。应该是name="city"
第二次......
答案 1 :(得分:0)
看起来php的邮件功能正在给出错误。你可以调试它。使用error_get_last()函数来获取错误。
$successfulMail = mail($recipient, $subject, $formcontent, $mailheader);
if (!$successfulMail) {
$errorMessage = error_get_last()['formcontent'];
}
你也可以做一个print_r(error_get_last())。
print_r(error_get_last());
请与我们分享错误,以便我们为您提供帮助。