PHP中的联系人表单验证重定向到空白页面



当我的表单被提交到'action'页面时,它是空白的。尽管我要检查邮箱,姓名等。它不会在空白页上显示任何错误。在过去的两天里,我一直在努力让这个工作。

下面是我的php代码:
<?php
if (isset($_POST['submit']) && !empty($_POST)) {
$myEmail = "xxxxxxxxxx"; //securyti XD
$timeStamp = date("dd/M/YY HH:i:s");
$body = "";
$fullName = $_POST['fullName'];
$customerEmail = $_POST['customerEmail'];
$chosenSubject = $_POST['subject'];
$message = $_POST['message'];
$nameRegularExpression = "/^[a-zA-Z]+$/";
$emailRegularExpression = "/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/";
$body .= "From: " . $fullName . " at $timeStamp" . "rn";
$body .= "Email: " . $customerEmail . "rn";
$body .= "Message: " . $message . "rn";
if (!preg_match($nameRegularExpression, $fullName) or empty($fullName)) {
echo "Your name is not filled out properly or not filled out at all";
}
if (!preg_match($emailRegularExpression, $customerEmail) or empty($customerEmail)) {
echo "Your mail is not valid or you forgot to fill it out";
}
if (empty($chosenSubject) or empty($message)) {
echo "Dont forget to choose subject or write a message";
}
else {
mail($myEmail, $chosenSubject, $body);
header("Location: mail_sent.php");
}
}

所以我也放了一个HTML希望它能帮助你帮助我哈哈这是我的html:

<form action="/public/contact_form.php" method="POST">
<label for="name">Full Name ✍🏻</label> <br />
<input
type="text"
id="fullName"
name="fullName"
placeholder="Full Name"
required
/>
<br />
<label for="yourEmail">Your Email 📧</label> <br />
<input
type="email"
id="customerEmail"
name="customerEmail"
placeholder="Your Email"
required
/>
<br />
<label for="subject"
>What is your reason for contacting us? 🧐</label
>
<br />
<select id="subject" name="subject">
<option value="basic">Pick a subject</option>
<option value="general">I have a question</option>
<option value="collaboration">
I want to offer a collaboration
</option>
<option value="other">
I have something else on my mind
</option>
</select>
<br />
<label for="message">Your message to us 👨🏻‍💻</label> <br />
<textarea
name="message"
id="message"
cols="40"
rows="6"
></textarea
><br />
<div class="form-buttons">
<button type="submit" class="send">SEND</button>
<button type="reset" class="messup">Wait, I messed up...</button>
</div>
</form>

确保错误报告是启用的。您可以将此代码添加到页面顶部。

ini_set('error_reporting', true);
error_reporting(E_ALL);

这就是你的问题:

<button type="submit" class="send">SEND</button>

如果你想检查提交,你应该添加一个名称和值,像这样:

<button type="submit" name="submit" value="1" class="send">SEND</button>

最新更新