我一直在尝试将 mail() 函数与 PHP 一起使用,但在测试联系表单时似乎无法将消息发送到我的电子邮件地址。它只是进入一个白屏,没有进一步......它甚至没有在下面显示成功消息。
这是PHP:
<?php
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$address = $_POST['address'];
$number = $_POST['number'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = 'Message from Reef website';
$to = 'myemail@hotmail.co.uk';
if (empty($name) || empty($address) || empty($number) || empty($email) || empty($subject) || empty($message)) {
if (empty($name))
$error['name'] = "Please enter your Full Name";
if (empty($name))
$error['address'] = "Please enter your address";
if (empty($name))
$error['number'] = "Please enter a contact number";
if (empty($email))
$error['email'] = "Please enter a valid Email Address";
if (empty($message))
$error['message'] = "Please write a message, enquiries or other concerns above";
}
else { //if not empty
$headers="From: {$email}\r\nReply-To: {$email}";
mail($to,$subject,$message,$headers);
$success = "Thank you! You're email has been sent.";
}
}
?>
这是我的 HTML 表单:
<form method="POST" action="mailer.php">
<table border="1">
<tr>
<td><label for="name" class="g">Name</label></td>
<td><input id="name" name="name" type="text" required autofocus></td>
</tr>
<tr>
<td><label for="address" class="g">Address</label></td>
<td><textarea rows="3" id="address" name="address" cols="50"></textarea></td>
</tr>
<tr>
<td><label for="number" class="g">Contact number</label></td>
<td><input id="number" name="text" type="text" required autofocus></td>
</tr>
<tr>
<td><label for="email" class="g">Email</label></td>
<td><input id="email" name="email" type="text" placeholder="example@domain.com" required autofocus></td>
</tr>
<tr>
<td><label for="message" class="g">Enquiry</label></td>
<td><textarea rows="3" id="message" name="message" cols="50"></textarea></td>
</tr>
</table>
<input type="submit" value="Submit" name="submit">
</form>
任何人都可以看到缺少什么吗?看看其他类似的问题,都和我的一样,但他们说他们有效。