我做了一个简单的联系表格,只是为了练习,但由于某种原因它不起作用。这是我的代码:
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
$required = array('name', 'email', 'onderwerp', 'bericht');
$error = false;
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}
if ($error) {
echo "All fields are required!";
} else {
$to = 'example@example.com';
$datum = date("d-m-Y H:i");
$ip = $_SERVER['REMOTE_ADDR'];
$naam = $_POST['name'];
$email = $_POST['email'];
$from = $_POST['email'];
$onderwerp = $_POST['onderwerp'];
$bericht = $_POST['bericht'];
$subject = "New e-mail!: $onderwerp";
$message .= $bericht . "\n\n";
$message .= "-----------------------------\n";
$message .= "From:: " . $name . " (" . $_POST['email'] . ")\n";
$message .= "IP-adres: " . $ip . "\n";
$message .= "Sent on $datum \n";
$headers = 'From: '.$_POST['email'];
$sent_email = mail($to, $subject, $message, $headers);
if (!$sent_email) {
echo "Mail has been sent!";
}
else
{
echo "Woops!";
}
}
}
else {
// Form has not been submitted
}
所以结果是糟糕!但我不知道为什么它不起作用:(提前谢谢!!