美好的一天,
我目前有一个联系表单用于我的一个网页但是只要有人输入信息并点击提交就会重新加载页面。日志中也没有错误。
这是我的HTML:
<form method="post">
<div class="form-row">
<div class="form-group col-md-4">
<label for="nameField">Name and Surname</label>
<input type="name" class="form-control" id="nameField" name="nameText" placeholder="" required>
</div>
<div class="form-group col-md-4">
<label for="emailField">Email address</label>
<input type="email" class="form-control" id="emailField" name="emailText" placeholder="name@example.com" required>
</div>
<div class="form-group col-md-4">
<label for="numberField">Contact Number</label>
<input type="number" class="form-control" id="numberield" name="numberText" placeholder="012 345 6789" required>
</div>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" id="message" name="messageText" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-dark btn-lg btn-block" name="submit">Submit</button>
</form>
和php:
<?php
if(isset($_POST['submit'])){
$cell = $_POST['numberText'];
$message = $_POST['messageText'];
$emailTo = "admin@example.com";
$subject = "Contact Request From ".$_POST['nameText'];
$content = "Phone: $cell \n Message: $message";
$headers = "From: ".$_POST['emailText'];
if (mail($emailTo, $subject, $content, $headers)) {
$message = "Your message has been sent";
echo "<script type='text/javascript'>alert('$message');</script>";
} else {
echo "<script type='text/javascript'>alert('Could not send message');</script>";
}
}
?>
有什么建议吗?
谢谢,))